use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class ResourceWebScriptHelper method executeResource.
/**
* Executes a single related Resource. The results are added to list of embedded results used by
* the ExecutionResult object.
*
* @param api Api
* @param params Params
* @param uniqueEntityId String
* @param resourceKey String
* @param resource ResourceWithMetadata
* @return Object
*/
private Object executeResource(final Api api, Params params, final String uniqueEntityId, final String resourceKey, final ResourceWithMetadata resource) {
try {
BeanPropertiesFilter paramFilter = null;
final Object[] resultOfExecution = new Object[1];
Map<String, BeanPropertiesFilter> filters = params.getRelationsFilter();
if (filters != null) {
paramFilter = filters.get(resourceKey);
}
final Params executionParams = Params.valueOf(paramFilter, uniqueEntityId, params.getRequest());
final WithResponse callBack = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
// Read only because this only occurs for GET requests
Object result = executor.executeAction(resource, executionParams, callBack);
return processAdditionsToTheResponse(null, api, null, executionParams, result);
} catch (NotFoundException e) {
// ignore, cannot access the object so don't embed it
if (logger.isDebugEnabled()) {
logger.debug("Ignored error, cannot access the object so can't embed it ", e);
}
} catch (PermissionDeniedException e) {
// ignore, cannot access the object so don't embed it
if (logger.isDebugEnabled()) {
logger.debug("Ignored error, cannot access the object so can't embed it ", e);
}
} catch (Throwable throwable) {
logger.warn("Failed to execute a RelatedResource for " + resourceKey + " " + throwable.getMessage());
}
// default
return null;
}
use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testLocateRelationshipProperties.
@Test
public void testLocateRelationshipProperties() {
Api api3 = Api.valueOf("alfrescomock", "private", "3");
Map<String, String> templateVars = new HashMap<String, String>();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "goat");
templateVars.put(ResourceLocator.ENTITY_ID, "herdId");
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "herd");
ResourceWithMetadata collResource;
try {
collResource = locator.locateResource(api3, templateVars, HttpMethod.PUT);
fail("Should throw an UnsupportedResourceOperationException");
} catch (UnsupportedResourceOperationException error) {
// this is correct
}
templateVars.put(ResourceLocator.PROPERTY, "content");
collResource = locator.locateResource(api3, templateVars, HttpMethod.GET);
assertNotNull(collResource);
assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
templateVars = new HashMap<String, String>();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
templateVars.put(ResourceLocator.PROPERTY, "content");
try {
// Tests by passing invalid propery
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
fail("Should throw an NotFoundException");
} catch (NotFoundException error) {
// this is correct
}
templateVars.put(ResourceLocator.PROPERTY, "photo");
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
assertNotNull(collResource);
assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
assertNotNull(collResource.getMetaData().getOperation(HttpMethod.PUT));
assertNotNull(collResource.getMetaData().getOperation(HttpMethod.DELETE));
}
use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class NodesImpl method getThumbnailDefs.
private List<ThumbnailDefinition> getThumbnailDefs(Set<String> renditionNames) {
List<ThumbnailDefinition> thumbnailDefs = null;
if (renditionNames != null) {
// If thumbnail generation has been configured off, then don't bother.
if (!thumbnailService.getThumbnailsEnabled()) {
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
thumbnailDefs = new ArrayList<>(renditionNames.size());
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
for (String renditionName : renditionNames) {
// Use the thumbnail registry to get the details of the thumbnail
ThumbnailDefinition thumbnailDef = registry.getThumbnailDefinition(renditionName);
if (thumbnailDef == null) {
throw new NotFoundException(renditionName + " is not registered.");
}
thumbnailDefs.add(thumbnailDef);
}
}
return thumbnailDefs;
}
use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method createRendition.
@Override
public void createRendition(NodeRef nodeRef, Rendition rendition, boolean executeAsync, Parameters parameters) {
// If thumbnail generation has been configured off, then don't bother.
if (!thumbnailService.getThumbnailsEnabled()) {
throw new DisabledServiceException("Thumbnail generation has been disabled.");
}
final NodeRef sourceNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
if (renditionNodeRef != null) {
throw new ConstraintViolatedException(rendition.getId() + " rendition already exists.");
}
// Use the thumbnail registry to get the details of the thumbnail
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
ThumbnailDefinition thumbnailDefinition = registry.getThumbnailDefinition(rendition.getId());
if (thumbnailDefinition == null) {
throw new NotFoundException(rendition.getId() + " is not registered.");
}
ContentData contentData = getContentData(sourceNodeRef, true);
// Check if anything is currently available to generate thumbnails for the specified mimeType
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef, thumbnailDefinition)) {
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' for " + contentData.getMimetype() + " as no transformer is currently available.");
}
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDefinition, serviceRegistry);
// Create thumbnail - or else queue for async creation
actionService.executeAction(action, sourceNodeRef, true, executeAsync);
}
use of org.alfresco.rest.framework.core.exceptions.NotFoundException in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method getContentNoValidation.
@Override
public BinaryResource getContentNoValidation(NodeRef sourceNodeRef, String renditionId, Parameters parameters) {
NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, renditionId, parameters);
// By default set attachment header (with rendition Id) unless attachment=false
boolean attach = true;
String attachment = parameters.getParameter("attachment");
if (attachment != null) {
attach = Boolean.valueOf(attachment);
}
final String attachFileName = (attach ? renditionId : null);
if (renditionNodeRef == null) {
boolean isPlaceholder = Boolean.valueOf(parameters.getParameter("placeholder"));
if (!isPlaceholder) {
throw new NotFoundException("Thumbnail was not found for [" + renditionId + ']');
}
String sourceNodeMimeType = null;
try {
sourceNodeMimeType = (sourceNodeRef != null ? getMimeType(sourceNodeRef) : null);
} catch (InvalidArgumentException e) {
// No content for node, e.g. ASSOC_AVATAR rather than ASSOC_PREFERENCE_IMAGE
}
// resource based on the content's mimeType and rendition id
String phPath = scriptThumbnailService.getMimeAwarePlaceHolderResourcePath(renditionId, sourceNodeMimeType);
if (phPath == null) {
// 404 since no thumbnail was found
throw new NotFoundException("Thumbnail was not found and no placeholder resource available for [" + renditionId + ']');
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Retrieving content from resource path [" + phPath + ']');
}
// get extension of resource
String ext = "";
int extIndex = phPath.lastIndexOf('.');
if (extIndex != -1) {
ext = phPath.substring(extIndex);
}
try {
final String resourcePath = "classpath:" + phPath;
InputStream inputStream = resourceLoader.getResource(resourcePath).getInputStream();
// create temporary file
File file = TempFileProvider.createTempFile(inputStream, "RenditionsApi-", ext);
return new FileBinaryResource(file, attachFileName);
} catch (Exception ex) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Couldn't load the placeholder." + ex.getMessage());
}
throw new ApiException("Couldn't load the placeholder.");
}
}
}
Map<QName, Serializable> nodeProps = nodeService.getProperties(renditionNodeRef);
ContentData contentData = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
Date modified = (Date) nodeProps.get(ContentModel.PROP_MODIFIED);
org.alfresco.rest.framework.resource.content.ContentInfo contentInfo = null;
if (contentData != null) {
contentInfo = new ContentInfoImpl(contentData.getMimetype(), contentData.getEncoding(), contentData.getSize(), contentData.getLocale());
}
// add cache settings
CacheDirective cacheDirective = new CacheDirective.Builder().setNeverCache(false).setMustRevalidate(false).setLastModified(modified).setETag(modified != null ? Long.toString(modified.getTime()) : null).setMaxAge(// one year (in seconds)
Long.valueOf(31536000)).build();
return new NodeBinaryResource(renditionNodeRef, ContentModel.PROP_CONTENT, contentInfo, attachFileName, cacheDirective);
}
Aggregations