Search in sources :

Example 46 with EntityNotFoundException

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();
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) InvitationExceptionForbidden(org.alfresco.service.cmr.invitation.InvitationExceptionForbidden) ResourceType(org.alfresco.service.cmr.invitation.Invitation.ResourceType) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 47 with EntityNotFoundException

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;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 48 with EntityNotFoundException

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);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Serializable(java.io.Serializable) HashMap(java.util.HashMap) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 49 with EntityNotFoundException

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);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 50 with EntityNotFoundException

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);
    }
}
Also used : EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork) ResponseWriter(org.alfresco.rest.framework.tools.ResponseWriter) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Aggregations

EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)66 NodeRef (org.alfresco.service.cmr.repository.NodeRef)28 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)24 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)16 QName (org.alfresco.service.namespace.QName)15 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 HashMap (java.util.HashMap)11 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)11 ArrayList (java.util.ArrayList)9 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)8 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)7 Serializable (java.io.Serializable)6 FileInfo (org.alfresco.service.cmr.model.FileInfo)6 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 ActivitiScriptNode (org.alfresco.repo.workflow.activiti.ActivitiScriptNode)5 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4