Search in sources :

Example 31 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class SitesImpl method getSiteContainers.

public PagingResults<SiteContainer> getSiteContainers(String siteId, Paging paging) {
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(), Util.getPagingRequest(paging));
    List<FileInfo> containerFileInfos = pagingResults.getPage();
    final List<SiteContainer> siteContainers = new ArrayList<SiteContainer>(containerFileInfos.size());
    for (FileInfo containerFileInfo : containerFileInfos) {
        NodeRef nodeRef = containerFileInfo.getNodeRef();
        String containerId = (String) nodeService.getProperty(nodeRef, SiteModel.PROP_COMPONENT_ID);
        SiteContainer siteContainer = new SiteContainer(containerId, nodeRef);
        siteContainers.add(siteContainer);
    }
    return new PagingResults<SiteContainer>() {

        @Override
        public List<SiteContainer> getPage() {
            return siteContainers;
        }

        @Override
        public boolean hasMoreItems() {
            return pagingResults.hasMoreItems();
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount() {
            return pagingResults.getTotalResultCount();
        }

        @Override
        public String getQueryExecutionId() {
            return null;
        }
    };
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PagingResults(org.alfresco.query.PagingResults) FileInfo(org.alfresco.service.cmr.model.FileInfo) ArrayList(java.util.ArrayList) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 32 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class SitesImpl method updateSite.

@Override
public Site updateSite(String siteId, SiteUpdate update, Parameters parameters) {
    if (logger.isDebugEnabled()) {
        logger.debug("Updating site, ID: " + siteId + ", site data: " + update + ", parameters: " + parameters);
    }
    // Get the site by ID (aka short name)
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    // Bind any provided values to the site info, allowing for "partial" updates.
    if (update.wasSet(Site.TITLE)) {
        siteInfo.setTitle(update.getTitle());
    }
    if (update.wasSet(Site.DESCRIPTION)) {
        siteInfo.setDescription(update.getDescription());
    }
    if (update.wasSet(Site.VISIBILITY)) {
        siteInfo.setVisibility(update.getVisibility());
    }
    // Validate the new details
    validateSite(new Site(siteInfo, null));
    // Perform the actual update.
    siteService.updateSite(siteInfo);
    return getSite(siteId);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 33 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class NodeTargetsRelation method delete.

@Override
@WebApiDescription(title = "Remove node assoc(s)")
public void delete(String sourceNodeId, String targetNodeId, Parameters parameters) {
    NodeRef srcNodeRef = nodes.validateNode(sourceNodeId);
    NodeRef tgtNodeRef = nodes.validateNode(targetNodeId);
    String assocTypeStr = parameters.getParameter(Nodes.PARAM_ASSOC_TYPE);
    QNamePattern assocTypeQName = nodes.getAssocType(assocTypeStr, false);
    if (assocTypeQName == null) {
        assocTypeQName = RegexQNamePattern.MATCH_ALL;
    }
    // note: even if assocType is provided, we currently don't use nodeService.removeAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
    // since silent it returns void even if nothing deleted, where as we return 404
    boolean found = false;
    List<AssociationRef> assocRefs = nodeAssocService.getTargetAssocs(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sourceNodeId), assocTypeQName);
    for (AssociationRef assocRef : assocRefs) {
        if (assocRef.getTargetRef().equals(tgtNodeRef)) {
            nodeAssocService.removeAssociation(srcNodeRef, tgtNodeRef, assocRef.getTypeQName());
            found = true;
        }
    }
    if (!found) {
        throw new EntityNotFoundException(sourceNodeId + "," + assocTypeStr + "," + targetNodeId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RegexQNamePattern(org.alfresco.service.namespace.RegexQNamePattern) QNamePattern(org.alfresco.service.namespace.QNamePattern) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 34 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method revertById.

@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
    Version v = findVersion(nodeId, versionId);
    if (v != null) {
        CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
        NodeRef nodeRef = v.getVersionedNodeRef();
        String versionComment = versionOptions.getComment();
        VersionType versionType = VersionType.MINOR;
        Boolean versionMajor = versionOptions.getMajorVersion();
        if ((versionMajor != null) && (versionMajor)) {
            versionType = VersionType.MAJOR;
        }
        Map<String, Serializable> versionProperties = new HashMap<>(2);
        versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
        if (versionComment != null) {
            versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
        }
        // cancel editing if we want to revert
        if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
            nodeRef = cociService.cancelCheckout(nodeRef);
        }
        // TODO review default for deep and/or whether we should make it an option
        versionService.revert(nodeRef, v, false);
        // Checkout/Checkin the node - to store the new version in version history
        NodeRef wcNodeRef = cociService.checkout(nodeRef);
        cociService.checkin(wcNodeRef, versionProperties);
        // get latest version
        v = versionService.getVersionHistory(nodeRef).getHeadVersion();
        Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
        mapVersionInfo(v, node);
        return node;
    }
    throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) Version(org.alfresco.service.cmr.version.Version) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionType(org.alfresco.service.cmr.version.VersionType) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Example 35 with EntityNotFoundException

use of org.alfresco.rest.framework.core.exceptions.EntityNotFoundException in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method readById.

@Override
@WebApiDescription(title = "Get version node info", description = "Return metadata for a specific version node")
public Node readById(String nodeId, String versionId, Parameters parameters) {
    Version v = findVersion(nodeId, versionId);
    if (v != null) {
        Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
        mapVersionInfo(v, node);
        return node;
    }
    throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Also used : Version(org.alfresco.service.cmr.version.Version) Node(org.alfresco.rest.api.model.Node) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

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