use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SiteMembershipRequestsImpl method rejectSiteMembershipRequest.
@Override
public void rejectSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection) {
SiteInfo siteInfo = sites.validateSite(siteId);
if (siteInfo == null) {
throw new EntityNotFoundException(siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with
// using the siteId from the url)
siteId = siteInfo.getShortName();
// Validate invitation.
Invitation invitation = getSiteInvitation(inviteeId, siteId);
if (invitation == null || !(invitation instanceof ModeratedInvitation)) {
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
}
ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
ResourceType resourceType = moderatedInvitation.getResourceType();
if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility())) {
// note: security, no indication that this has a different visibility
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
}
String reason = null;
if (siteMembershipRejection != null && !(siteMembershipRejection.getComment() == null || siteMembershipRejection.getComment().isEmpty())) {
reason = siteMembershipRejection.getComment();
}
try {
invitationService.reject(invitation.getInviteId(), reason);
} catch (InvitationExceptionForbidden ex) {
throw new PermissionDeniedException();
}
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method validateSite.
public SiteInfo validateSite(NodeRef guid) {
SiteInfo siteInfo = null;
if (guid == null) {
throw new InvalidArgumentException("guid is null");
}
nodes.validateNode(guid);
QName type = nodeService.getType(guid);
boolean isSiteNodeRef = dictionaryService.isSubClass(type, SiteModel.TYPE_SITE);
if (isSiteNodeRef) {
siteInfo = siteService.getSite(guid);
if (siteInfo == null) {
// not a site
throw new InvalidArgumentException(guid.getId() + " is not a site");
}
} else {
// site does not exist
throw new EntityNotFoundException(guid.getId());
}
return siteInfo;
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class SitesImpl method addFavouriteSite.
public void addFavouriteSite(String personId, FavouriteSite favouriteSite) {
personId = people.validatePerson(personId);
String siteId = favouriteSite.getId();
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
StringBuilder prefKey = new StringBuilder(FAVOURITE_SITES_PREFIX);
prefKey.append(siteId);
String value = (String) preferenceService.getPreference(personId, prefKey.toString());
boolean isFavouriteSite = (value == null ? false : value.equalsIgnoreCase("true"));
if (isFavouriteSite) {
throw new ConstraintViolatedException("Site " + siteId + " is already a favourite site");
}
prefKey = new StringBuilder(FAVOURITE_SITES_PREFIX);
prefKey.append(siteId);
Map<String, Serializable> preferences = new HashMap<String, Serializable>(1);
preferences.put(prefKey.toString(), Boolean.TRUE);
preferenceService.setPreferences(personId, preferences);
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class NodeSecondaryChildrenRelation method delete.
@Override
@WebApiDescription(title = "Remove secondary child assoc(s)")
public void delete(String parentNodeId, String childNodeId, Parameters parameters) {
NodeRef parentNodeRef = nodes.validateNode(parentNodeId);
NodeRef childNodeRef = nodes.validateNode(childNodeId);
String assocTypeStr = parameters.getParameter(Nodes.PARAM_ASSOC_TYPE);
QName assocTypeQName = nodes.getAssocType(assocTypeStr, false);
List<ChildAssociationRef> assocRefs = nodeService.getChildAssocs(parentNodeRef);
boolean found = false;
for (ChildAssociationRef assocRef : assocRefs) {
if (!assocRef.getChildRef().equals(childNodeRef)) {
continue;
}
if (assocTypeQName != null) {
if (assocTypeQName.equals(assocRef.getTypeQName())) {
if (assocRef.isPrimary()) {
throw new InvalidArgumentException("Cannot use secondary-children to delete primary assoc: " + parentNodeId + "," + assocTypeStr + "," + childNodeId);
}
boolean existed = nodeService.removeSecondaryChildAssociation(assocRef);
if (existed) {
found = true;
}
}
} else {
if (!assocRef.isPrimary()) {
boolean existed = nodeService.removeSecondaryChildAssociation(assocRef);
if (existed) {
found = true;
}
}
}
}
if (!found) {
throw new EntityNotFoundException(parentNodeId + "," + assocTypeStr + "," + childNodeId);
}
}
use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.
the class NetworkWebScriptGet method execute.
@Override
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException {
try {
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// apply content type
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
String personId = AuthenticationUtil.getFullyAuthenticatedUser();
String networkId = TenantUtil.getCurrentDomain();
PersonNetwork networkMembership = networks.getNetwork(personId, networkId);
if (networkMembership != null) {
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
// done automatically by the api framework).
Object wrapped = helper.processAdditionsToTheResponse(res, Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMembership);
objectMapper.writeValue(generator, wrapped);
} else {
throw new EntityNotFoundException(networkId);
}
}
});
return null;
}
}, true, true);
} catch (ApiException | WebScriptException apiException) {
renderException(apiException, res, assistant);
} catch (RuntimeException runtimeException) {
renderException(runtimeException, res, assistant);
}
}
Aggregations