use of org.forgerock.json.resource.PreconditionFailedException in project OpenAM by OpenRock.
the class SitesResourceProvider method deleteInstance.
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String id, DeleteRequest request) {
ResourceResponse site;
SSOToken token;
try {
token = getSsoToken(context);
site = getSite(token, id);
} catch (SMSException | SSOException | ConfigurationException e) {
debug.error("Could not read site {}", id, e);
return new InternalServerErrorException("Could not read site").asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
try {
if (!site.getRevision().equals(request.getRevision())) {
return new PreconditionFailedException("Revision did not match").asPromise();
} else if (!SiteConfiguration.listServers(token, id).isEmpty()) {
return new PreconditionFailedException("Site still has servers attached to it").asPromise();
} else if (!SiteConfiguration.deleteSite(token, id)) {
return new InternalServerErrorException("Could not delete site: " + id).asPromise();
} else {
return newResultPromise(site);
}
} catch (SSOException | SMSException | ConfigurationException e) {
debug.error("Could not delete site {}", id, e);
return new InternalServerErrorException("Could not delete site").asPromise();
}
}
use of org.forgerock.json.resource.PreconditionFailedException in project OpenAM by OpenRock.
the class SitesResourceProvider method updateInstance.
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String id, UpdateRequest request) {
JsonValue content = request.getContent();
try {
validWriteOperation(content, id);
} catch (BadRequestException e) {
return e.asPromise();
}
ResourceResponse site;
SSOToken token;
try {
token = getSsoToken(context);
site = getSite(token, id);
} catch (SMSException | SSOException | ConfigurationException e) {
debug.error("Could not read site {}", id, e);
return new InternalServerErrorException("Could not read site").asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
try {
if (!site.getRevision().equals(request.getRevision())) {
return new PreconditionFailedException("Revision did not match").asPromise();
}
SiteConfiguration.setSitePrimaryURL(token, id, content.get("url").asString());
SiteConfiguration.setSiteSecondaryURLs(token, id, content.get("secondaryURLs").asSet());
return newResultPromise(getSite(token, id));
} catch (SSOException | SMSException | ConfigurationException e) {
debug.error("Could not update site {}", id, e);
return new InternalServerErrorException("Could not update site").asPromise();
} catch (NotFoundException e) {
return new InternalServerErrorException("Could not read site after just updating it", e).asPromise();
}
}
Aggregations