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;
}
};
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations