use of org.alfresco.service.cmr.thumbnail.ThumbnailService in project alfresco-remote-api by Alfresco.
the class TestPeople method updateAvatar.
@Test
public void updateAvatar() throws PublicApiException, IOException, InterruptedException {
final String person1 = account1PersonIt.next();
final String person2 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person2));
AuthenticationUtil.setFullyAuthenticatedUser(person2);
// Update allowed when no existing avatar
{
// Pre-condition: no avatar exists
NodeRef personRef = personService.getPerson(person2, false);
deleteAvatarDirect(personRef);
people.getAvatar(person2, false, 404);
// TODO: What do we expect the 200 response body to be? Currently it's the person JSON - doesn't seem right.
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
HttpResponse response = people.updateAvatar(person2, avatar.getFile(), 200);
// TODO: ideally, this should be a "direct" retrieval to isolate update from get
people.getAvatar(person2, false, 200);
}
// Update existing avatar
{
// Pre-condition: avatar exists
people.getAvatar(person2, false, 200);
ClassPathResource avatar = new ClassPathResource("test.jpg");
HttpResponse response = people.updateAvatar(person2, avatar.getFile(), 200);
people.getAvatar(person2, false, 200);
// -me- alias
people.updateAvatar(person2, avatar.getFile(), 200);
people.getAvatar("-me-", false, 200);
}
// 400: invalid user ID
{
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar("joe@@bloggs.example.com", avatar.getFile(), 404);
}
// 401: authentication failure
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "Wr0ngP4ssw0rd!"));
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(account1Admin, avatar.getFile(), 401);
}
// 403: permission denied
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(person2, avatar.getFile(), 403);
// Person can update themself
people.updateAvatar(person1, avatar.getFile(), 200);
// Admin can update someone else
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
people.updateAvatar(person1, avatar.getFile(), 200);
}
// 404: non-existent person
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
// Pre-condition: non-existent person
String nonPerson = "joebloggs@" + account1.getId();
people.getPerson(nonPerson, 404);
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(nonPerson, avatar.getFile(), 404);
}
// 413: content exceeds individual file size limit
{
// Test content size limit
final ContentLimitProvider.SimpleFixedLimitProvider limitProvider = applicationContext.getBean("defaultContentLimitProvider", ContentLimitProvider.SimpleFixedLimitProvider.class);
final long defaultSizeLimit = limitProvider.getSizeLimit();
// 20 KB
limitProvider.setSizeLimitString("20000");
try {
// ~26K
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(person1, avatar.getFile(), 413);
} finally {
limitProvider.setSizeLimitString(Long.toString(defaultSizeLimit));
}
}
// 501: thumbnails disabled
{
ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class);
// Disable thumbnail generation
thumbnailService.setThumbnailsEnabled(false);
try {
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(person1, avatar.getFile(), 501);
} finally {
thumbnailService.setThumbnailsEnabled(true);
}
}
}
use of org.alfresco.service.cmr.thumbnail.ThumbnailService in project alfresco-repository by Alfresco.
the class ScriptNode method getThumbnailDefinitions.
/**
* Returns the names of the thumbnail defintions that can be applied to the content property of
* this node.
* <p>
* Thumbanil defintions only appear in this list if they can produce a thumbnail for the content
* found in the content property. This will be determined by looking at the mimetype of the content
* and the destinatino mimetype of the thumbnail.
*
* @return String[] array of thumbnail names that are valid for the current content type
*/
public String[] getThumbnailDefinitions() {
ThumbnailService thumbnailService = this.services.getThumbnailService();
List<String> result = new ArrayList<String>(7);
Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
if (ContentData.hasContent(contentData)) {
String mimetype = contentData.getMimetype();
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(mimetype, contentData.getSize());
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
result.add(thumbnailDefinition.getName());
}
}
return (String[]) result.toArray(new String[result.size()]);
}
use of org.alfresco.service.cmr.thumbnail.ThumbnailService in project alfresco-repository by Alfresco.
the class ScriptNode method createThumbnail.
/**
* Creates a thumbnail for the content property of the node.
*
* The thumbnail name corresponds to pre-set thumbnail details stored in the
* repository.
*
* If the thumbnail is created asynchronously then the result will be null and creation
* of the thumbnail will occure at some point in the background.
*
* If foce param specified system.thumbnail.generate is ignoring. Could be used for preview creation
*
* @param thumbnailName the name of the thumbnail
* @param async indicates whether the thumbnail is create asynchronously or not
* @param force ignore system.thumbnail.generate=false
* @return ScriptThumbnail the newly create thumbnail node or null if async creation occures
*
* @deprecated The async flag in the method signature will not be applicable as all of
* the future transformations will be asynchronous
*/
@Deprecated
public ScriptThumbnail createThumbnail(String thumbnailName, boolean async, boolean force) {
final ThumbnailService thumbnailService = services.getThumbnailService();
ScriptThumbnail result = null;
// We need to create preview for node even if system.thumbnail.generate=false
if (force || thumbnailService.getThumbnailsEnabled()) {
// Use the thumbnail registy to get the details of the thumbail
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
if (details == null) {
// Throw exception
throw new ScriptException("The thumbnail name '" + thumbnailName + "' is not registered");
}
// If there's nothing currently registered to generate thumbnails for the
// specified mimetype, then log a message and bail out
String nodeMimeType = getMimetype();
Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
if (!ContentData.hasContent(contentData)) {
if (logger.isDebugEnabled())
logger.debug("Unable to create thumbnail '" + details.getName() + "' as there is no content");
return null;
}
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), nodeMimeType, getSize(), nodeRef, details)) {
logger.info("Unable to create thumbnail '" + details.getName() + "' for " + nodeMimeType + " as no transformer is currently available.");
return null;
}
// Have the thumbnail created
if (async == false) {
try {
// Create the thumbnail
NodeRef thumbnailNodeRef = thumbnailService.createThumbnail(this.nodeRef, ContentModel.PROP_CONTENT, details.getMimetype(), details.getTransformationOptions(), details.getName());
// Create the thumbnail script object
result = new ScriptThumbnail(thumbnailNodeRef, this.services, this.scope);
} catch (AlfrescoRuntimeException e) {
Throwable rootCause = e.getRootCause();
if (rootCause instanceof UnimportantTransformException) {
logger.debug("Unable to create thumbnail '" + details.getName() + "' as " + rootCause.getMessage());
return null;
}
throw e;
}
} else {
RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(thumbnailName);
if (renditionDefinition != null) {
renditionService2.render(nodeRef, thumbnailName);
} else {
Action action = ThumbnailHelper.createCreateThumbnailAction(details, services);
// Queue async creation of thumbnail
this.services.getActionService().executeAction(action, this.nodeRef, true, true);
}
}
}
return result;
}
use of org.alfresco.service.cmr.thumbnail.ThumbnailService in project alfresco-repository by Alfresco.
the class ConfigurationDataCollectorTest method setUp.
@Before
public void setUp() {
smartFoldersBundle = mock(SpringExtensionBundle.class);
mockDescriptorDAO = mock(DescriptorDAO.class);
mockServerDescriptorDAO = mock(DescriptorDAO.class);
mockCollectorService = mock(HBDataCollectorService.class);
mockScheduler = mock(HeartBeatJobScheduler.class);
Descriptor mockDescriptor = mock(Descriptor.class);
when(mockDescriptor.getId()).thenReturn("mock_id");
when(mockServerDescriptorDAO.getDescriptor()).thenReturn(mockDescriptor);
when(mockDescriptorDAO.getDescriptor()).thenReturn(mockDescriptor);
BasicDataSource mockBasicDataSource = mock(BasicDataSource.class);
RepoUsageComponent mockRepoUsageComponent = mock(RepoUsageComponent.class);
ServerModeProvider mockServerModeProvider = mock(ServerModeProvider.class);
when(mockServerModeProvider.getServerMode()).thenReturn(SERVER_MODE);
ChildApplicationContextFactory mockFileServerSubsystem = mock(ChildApplicationContextFactory.class);
WebDavService mockWebDavService = mock(WebDavService.class);
ThumbnailService mockThumbnailService = mock(ThumbnailService.class);
ChildApplicationContextFactory mockActivitiesFeedSubsystem = mock(ChildApplicationContextFactory.class);
WorkflowAdminService mockWorkflowAdminService = mock(WorkflowAdminService.class);
ChildApplicationContextFactory mockInboundSMTPSubsystem = mock(ChildApplicationContextFactory.class);
ChildApplicationContextFactory mockImapSubsystem = mock(ChildApplicationContextFactory.class);
ChildApplicationContextFactory mockReplication = mock(ChildApplicationContextFactory.class);
// mock modules and module service
ModuleService mockModuleService = mock(ModuleService.class);
ModuleDetails mockInstalledModule1 = mock(ModuleDetails.class);
when(mockInstalledModule1.getId()).thenReturn(INSTALLED_MODULE_ID_1);
when(mockInstalledModule1.getModuleVersionNumber()).thenReturn(INSTALLED_MODULE_VERSION_1);
ModuleDetails mockInstalledModule2 = mock(ModuleDetails.class);
when(mockInstalledModule2.getId()).thenReturn(INSTALLED_MODULE_ID_2);
when(mockInstalledModule2.getModuleVersionNumber()).thenReturn(INSTALLED_MODULE_VERSION_2);
ModuleDetails mockMissingModule = mock(ModuleDetails.class);
when(mockMissingModule.getId()).thenReturn(MISSING_MODULE_ID_1);
when(mockMissingModule.getModuleVersionNumber()).thenReturn(MISSING_MODULE_VERSION_1);
when(mockModuleService.getAllModules()).thenReturn(Arrays.asList(mockInstalledModule1, mockInstalledModule2));
when(mockModuleService.getMissingModules()).thenReturn(Arrays.asList(mockMissingModule));
// mock audit applications and audit service
AuditService mockAuditService = mock(AuditService.class);
AuditService.AuditApplication mockAuditApp = mock(AuditService.AuditApplication.class);
when(mockAuditApp.isEnabled()).thenReturn(AUDIT_APP_ENABLED);
Map<String, AuditService.AuditApplication> auditApps = new HashMap<>();
auditApps.put(AUDIT_APP_NAME, mockAuditApp);
TransactionService mockTransactionService = mock(TransactionService.class);
RetryingTransactionHelper mockRetryingTransactionHelper = mock(RetryingTransactionHelper.class);
// Mock transaction service calls
when(mockRetryingTransactionHelper.doInTransaction(any(RetryingTransactionHelper.RetryingTransactionCallback.class), anyBoolean())).thenReturn(// First call made by the collector to get the server readOnly value via transformation service
true).thenReturn(// Second call to get the audit applications
auditApps);
when(mockTransactionService.getRetryingTransactionHelper()).thenReturn(mockRetryingTransactionHelper);
// mock authentication chain
DefaultChildApplicationContextManager mockAuthenticationSubsystem = mock(DefaultChildApplicationContextManager.class);
configurationCollector = new ConfigurationDataCollector("acs.repository.configuration", "1.0", "0 0 0 ? * SUN", mockScheduler);
configurationCollector.setHbDataCollectorService(mockCollectorService);
configurationCollector.setCurrentRepoDescriptorDAO(mockDescriptorDAO);
configurationCollector.setSmartFoldersBundle(smartFoldersBundle);
configurationCollector.setDataSource(mockBasicDataSource);
configurationCollector.setTransactionService(mockTransactionService);
configurationCollector.setRepoUsageComponent(mockRepoUsageComponent);
configurationCollector.setServerModeProvider(mockServerModeProvider);
configurationCollector.setFileServersSubsystem(mockFileServerSubsystem);
configurationCollector.setWebdavService(mockWebDavService);
configurationCollector.setThumbnailService(mockThumbnailService);
configurationCollector.setActivitiesFeedSubsystem(mockActivitiesFeedSubsystem);
configurationCollector.setWorkflowAdminService(mockWorkflowAdminService);
configurationCollector.setInboundSMTPSubsystem(mockInboundSMTPSubsystem);
configurationCollector.setImapSubsystem(mockImapSubsystem);
configurationCollector.setReplicationSubsystem(mockReplication);
configurationCollector.setModuleService(mockModuleService);
configurationCollector.setAuditService(mockAuditService);
configurationCollector.setAuthenticationSubsystem(mockAuthenticationSubsystem);
collectedData = configurationCollector.collectData();
}
use of org.alfresco.service.cmr.thumbnail.ThumbnailService in project alfresco-remote-api by Alfresco.
the class RenditionsTest method testCreateRenditionOnUpload.
/**
* Tests create rendition when on upload/create of a file
*
* <p>POST:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/children}
*/
@Test
public void testCreateRenditionOnUpload() throws Exception {
String userId = userOneN1.getId();
setRequestContext(networkN1.getId(), userOneN1.getId(), null);
// Create a folder within the site document's library
String folderName = "folder" + System.currentTimeMillis();
String folder_Id = addToDocumentLibrary(userOneN1Site, folderName, TYPE_CM_FOLDER, userId);
// Create multipart request - pdf file
String renditionName = "doclib";
String fileName = "quick.pdf";
File file = getResourceFile(fileName);
MultiPartRequest reqBody = MultiPartBuilder.create().setFileData(new FileData(fileName, file)).setRenditions(Collections.singletonList(renditionName)).build();
// Upload quick.pdf file into 'folder' - including request to create 'doclib' thumbnail
HttpResponse response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String contentNodeId = document.getId();
// wait and check that rendition is created ...
Rendition rendition = waitAndGetRendition(contentNodeId, null, renditionName);
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
Map<String, String> params = new HashMap<>();
params.put("placeholder", "false");
response = getSingle(getNodeRenditionsUrl(contentNodeId), ("doclib/content"), params, 200);
assertNotNull(response.getResponseAsBytes());
if (isOpenOfficeAvailable()) {
// Create multipart request - Word doc file
renditionName = "doclib";
fileName = "farmers_markets_list_2003.doc";
file = getResourceFile(fileName);
reqBody = MultiPartBuilder.create().setFileData(new FileData(fileName, file)).setRenditions(Collections.singletonList(renditionName)).build();
// Upload file into 'folder' - including request to create 'doclib' thumbnail
response = post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
contentNodeId = document.getId();
assertRenditionCreatedWithWait(contentNodeId, renditionName);
}
/* RA-834: commented-out since not currently applicable for empty file
Document d1 = new Document();
d1.setName("d1.txt");
d1.setNodeType("cm:content");
ContentInfo ci = new ContentInfo();
ci.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
d1.setContent(ci);
// create empty file including request to generate a thumbnail
renditionName = "doclib";
response = post(getNodeChildrenUrl(folder_Id), userId, toJsonAsStringNonNull(d1), "?renditions="+renditionName, 201);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
String d1Id = documentResp.getId();
// wait and check that rendition is created ...
rendition = waitAndGetRendition(userId, d1Id, renditionName);
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
*/
// Multiple renditions requested
reqBody = MultiPartBuilder.create().setFileData(new FileData(fileName, file)).setAutoRename(true).setRenditions(Arrays.asList(new String[] { "doclib,imgpreview" })).build();
post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
// Unknown rendition
reqBody = MultiPartBuilder.create().setFileData(new FileData(fileName, file)).setAutoRename(true).setRenditions(Arrays.asList(new String[] { "unknown" })).build();
post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 404);
// ThumbnailService is disabled
ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class);
thumbnailService.setThumbnailsEnabled(false);
try {
// Create multipart request
String txtFileName = "quick-1.txt";
File txtFile = getResourceFile(fileName);
reqBody = MultiPartBuilder.create().setFileData(new FileData(txtFileName, txtFile)).setRenditions(Arrays.asList(new String[] { "doclib" })).build();
post(getNodeChildrenUrl(folder_Id), reqBody.getBody(), null, reqBody.getContentType(), 201);
} finally {
thumbnailService.setThumbnailsEnabled(true);
}
}
Aggregations