|
|
@@ -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()); |
|
|
|
|
|
|
|