Explorar el Código

add site context to AppMatchersResource

tags/v1.0.3
Jonathan Cobb hace 4 años
padre
commit
924973fd0f
Se han modificado 3 ficheros con 40 adiciones y 6 borrados
  1. +9
    -0
      bubble-server/src/main/java/bubble/dao/app/AppMatcherDAO.java
  2. +23
    -6
      bubble-server/src/main/java/bubble/resources/app/AppMatchersResource.java
  3. +8
    -0
      bubble-server/src/main/java/bubble/resources/app/AppSitesResource.java

+ 9
- 0
bubble-server/src/main/java/bubble/dao/app/AppMatcherDAO.java Ver fichero

@@ -51,6 +51,15 @@ public class AppMatcherDAO extends AppTemplateEntityDAO<AppMatcher> {
return findByFields("account", account, "enabled", true, "connCheck", true);
}

public List<AppMatcher> findByAccountAndAppAndSite(String accountUuid, String appUuid, String siteUuid) {
return findByFields("account", accountUuid, "app", appUuid, "site", siteUuid);
}

public AppMatcher findByAccountAndAppAndSiteAndId(String accountUuid, String appUuid, String siteUuid, String id) {
final AppMatcher found = findByUniqueFields("account", accountUuid, "app", appUuid, "site", siteUuid, "name", id);
return found != null ? found : findByUniqueFields("account", accountUuid, "app", appUuid, "site", siteUuid, "uuid", id);
}

@Override public Object preCreate(AppMatcher matcher) {
if (matcher.getConnCheck() == null) matcher.setConnCheck(false);
if (matcher.getRequestCheck() == null) matcher.setRequestCheck(false);


+ 23
- 6
bubble-server/src/main/java/bubble/resources/app/AppMatchersResource.java Ver fichero

@@ -23,6 +23,7 @@ import javax.ws.rs.Produces;
import java.util.List;

import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON;
import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx;
import static org.cobbzilla.wizard.resources.ResourceUtil.notFoundEx;

@Consumes(APPLICATION_JSON)
@@ -33,19 +34,28 @@ public class AppMatchersResource extends AccountOwnedResource<AppMatcher, AppMat
@Autowired private AppSiteDAO siteDAO;
@Autowired protected BubbleDomainDAO domainDAO;

@Getter private BubbleApp app;
@Getter private final BubbleApp app;
@Getter private AppSite site;

public AppMatchersResource(Account account, BubbleApp app) {
super(account);
this.app = app;
}
public AppMatchersResource(Account account, BubbleApp app, AppSite site) {
this(account, app);
this.site = site;
}

@Override protected List<AppMatcher> list(ContainerRequest ctx) {
return getDao().findByAccountAndApp(getAccountUuid(ctx), app.getUuid());
return site == null
? getDao().findByAccountAndApp(getAccountUuid(ctx), app.getUuid())
: getDao().findByAccountAndAppAndSite(getAccountUuid(ctx), app.getUuid(), site.getUuid());
}

@Override protected AppMatcher find(ContainerRequest ctx, String id) {
return getDao().findByAccountAndAppAndId(getAccountUuid(ctx), app.getUuid(), id);
return site == null
? getDao().findByAccountAndAppAndId(getAccountUuid(ctx), app.getUuid(), id)
: getDao().findByAccountAndAppAndSiteAndId(getAccountUuid(ctx), app.getUuid(), site.getUuid(), id);
}

@Override protected AppMatcher setReferences(ContainerRequest ctx, Account caller, AppMatcher matcher) {
@@ -53,9 +63,16 @@ public class AppMatchersResource extends AccountOwnedResource<AppMatcher, AppMat
if (rule == null) throw notFoundEx(matcher.getRule());
matcher.setRule(rule.getUuid());

final AppSite site = siteDAO.findByAccountAndAppAndId(getAccountUuid(ctx), app.getUuid(), matcher.getSite());
if (site == null) throw notFoundEx(matcher.getSite());
matcher.setSite(site.getUuid());
if (site == null) {
final AppSite site = siteDAO.findByAccountAndAppAndId(getAccountUuid(ctx), app.getUuid(), matcher.getSite());
if (site == null) throw notFoundEx(matcher.getSite());
matcher.setSite(site.getUuid());
} else {
if (matcher.getSite() != null && !(matcher.getSite().equals(getSite().getUuid()) || matcher.getSite().equals(getSite().getName()))) {
throw invalidEx("err.site.mismatch");
}
matcher.setSite(site.getUuid());
}

matcher.setApp(app.getUuid());



+ 8
- 0
bubble-server/src/main/java/bubble/resources/app/AppSitesResource.java Ver fichero

@@ -70,6 +70,14 @@ public class AppSitesResource extends AccountOwnedTemplateResource<AppSite, AppS
return ok(getDao().update(found.setEnabled(false)));
}

@Path("/{id}"+EP_MATCHERS)
public AppMatchersResource getSiteMatchers(@Context ContainerRequest ctx,
@PathParam("id") String id) {
final AppSite site = find(ctx, id);
if (site == null) throw notFoundEx(id);
return configuration.subResource(AppMatchersResource.class, getAccount(account, ctx), app, site);
}

@Path("/{id}"+EP_DATA)
public AppSiteDataResource getSiteData(@Context ContainerRequest ctx,
@PathParam("id") String id) {


Cargando…
Cancelar
Guardar