use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.
the class ThumbnailServiceTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");
this.contentService = (ContentService) getServer().getApplicationContext().getBean("ContentService");
this.repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
try {
this.transactionService = (TransactionServiceImpl) getServer().getApplicationContext().getBean("transactionComponent");
} catch (ClassCastException e) {
throw new AlfrescoRuntimeException("The ThumbnailServiceTest needs direct access to the TransactionServiceImpl");
}
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
this.testRoot = this.repositoryHelper.getCompanyHome();
// Get test content
InputStream pdfStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_doc.pdf");
assertNotNull(pdfStream);
InputStream jpgStream = ThumbnailServiceTest.class.getClassLoader().getResourceAsStream("org/alfresco/repo/web/scripts/thumbnail/test_image.jpg");
assertNotNull(jpgStream);
String guid = GUID.generate();
// Create new nodes and set test content
FileInfo fileInfoPdf = this.fileFolderService.create(this.testRoot, "test_doc" + guid + ".pdf", ContentModel.TYPE_CONTENT);
this.pdfNode = fileInfoPdf.getNodeRef();
ContentWriter contentWriter = this.contentService.getWriter(fileInfoPdf.getNodeRef(), ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_PDF);
contentWriter.putContent(pdfStream);
FileInfo fileInfoJpg = this.fileFolderService.create(this.testRoot, "test_image" + guid + ".jpg", ContentModel.TYPE_CONTENT);
this.jpgNode = fileInfoJpg.getNodeRef();
contentWriter = this.contentService.getWriter(fileInfoJpg.getNodeRef(), ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_IMAGE_JPEG);
contentWriter.putContent(jpgStream);
}
use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.
the class UnlockMethodTest method unlockCheckedOutNode.
/**
* Test that it is impossible to unlock a checked out node
*
* @throws Exception
*/
@Test
public void unlockCheckedOutNode() throws Exception {
setUpPreconditionForCheckedOutTest();
try {
String lockToken = fileNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + this.userName;
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
request.setRequestURI("/" + TEST_FILE_NAME);
WebDAVHelper davHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
unlockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
unlockMethod.parseRequestHeaders();
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
unlockMethod.executeImpl();
return null;
}
});
fail("Exception should have been thrown, but wasn't.");
} catch (AlfrescoRuntimeException e) {
if (e.getCause() instanceof WebDAVServerException) {
WebDAVServerException ee = (WebDAVServerException) e.getCause();
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, ee.getHttpStatusCode());
} else {
fail("Incorrect exception thrown.");
}
} catch (WebDAVServerException e) {
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, e.getHttpStatusCode());
} finally {
// clear context for current user
this.authenticationComponent.clearCurrentSecurityContext();
// delete test store as system user
this.authenticationComponent.setSystemUserAsCurrentUser();
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
if (nodeService.exists(storeRef)) {
nodeService.deleteStore(storeRef);
}
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
}
}
use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.
the class CommentsApiTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
ApplicationContext appContext = getServer().getApplicationContext();
fileFolderService = (FileFolderService) appContext.getBean("fileFolderService");
transactionService = (TransactionService) appContext.getBean("transactionService");
searchService = (SearchService) appContext.getBean("SearchService");
nodeService = (NodeService) appContext.getBean("nodeService");
namespaceService = (NamespaceService) appContext.getBean("namespaceService");
versionService = (VersionService) appContext.getBean("versionService");
personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
permissionService = (PermissionServiceSPI) getServer().getApplicationContext().getBean("permissionService");
permissionModelDAO = (ModelDAO) getServer().getApplicationContext().getBean("permissionsModelDAO");
siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService");
activityService = (ActivityService) getServer().getApplicationContext().getBean("activityService");
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) getServer().getApplicationContext().getBean("ActivitiesFeed");
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
txn = transactionService.getUserTransaction();
txn.begin();
// Get Company Home
rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
List<NodeRef> results = searchService.selectNodes(rootNodeRef, "/app:company_home", null, namespaceService, false);
if (results.size() == 0) {
throw new AlfrescoRuntimeException("Can't find /app:company_home");
}
companyHomeNodeRef = results.get(0);
// Get Shared
results = searchService.selectNodes(rootNodeRef, "/app:company_home/app:shared", null, namespaceService, false);
if (results.size() == 0) {
throw new AlfrescoRuntimeException("Can't find /app:company_home/app:shared");
}
sharedHomeNodeRef = results.get(0);
results = searchService.selectNodes(rootNodeRef, "/app:company_home/cm:Commenty", null, namespaceService, false);
if (results.size() > 0) {
fileFolderService.delete(results.get(0));
}
nodeRef = fileFolderService.create(companyHomeNodeRef, "Commenty", ContentModel.TYPE_CONTENT).getNodeRef();
versionService.ensureVersioningEnabled(nodeRef, null);
nodeService.setProperty(nodeRef, ContentModel.PROP_AUTO_VERSION_PROPS, true);
createUser(USER2);
createUser(USER_TEST);
txn.commit();
AuthenticationUtil.clearCurrentSecurityContext();
// MNT-12082
// Authenticate as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// Create test site
// - only create the site if it doesn't already exist
SiteInfo siteInfo = siteService.getSite(SITE_SHORT_NAME);
if (siteInfo == null) {
siteInfo = siteService.createSite("SomeTestSite", SITE_SHORT_NAME, "SiteTitle", "SiteDescription", SiteVisibility.PUBLIC);
}
NodeRef docLibContainer = siteService.getContainer(SITE_SHORT_NAME, DOCLIB_CONTAINER);
if (docLibContainer == null) {
siteService.createContainer(SITE_SHORT_NAME, DOCLIB_CONTAINER, ContentModel.TYPE_FOLDER, null);
}
txn = transactionService.getUserTransaction();
txn.begin();
// Create users
createUser(USER_ONE, SiteModel.SITE_CONSUMER);
createUser(USER_TWO, SiteModel.SITE_CONTRIBUTOR);
createUser(USER_THREE, SiteModel.SITE_COLLABORATOR);
createUser(USER_FOUR, SiteModel.SITE_COLLABORATOR);
// Create site page
sitePage = nodeService.createNode(siteInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "test"), ContentModel.TYPE_CONTENT).getChildRef();
txn.commit();
}
use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.
the class AuditImpl method getQueryResultAuditEntriesByNodeRef.
private List<AuditEntry> getQueryResultAuditEntriesByNodeRef(NodeRef nodeRef, AuditEntriesByNodeIdQueryWalker propertyWalker, List<String> includeParam, boolean forward, int limit) {
final List<AuditEntry> results = new ArrayList<>();
String auditAppId = "alfresco-access";
String auditApplicationName = AuthenticationUtil.runAs(new RunAsWork<String>() {
public String doWork() throws Exception {
return findAuditAppByIdOr404(auditAppId).getName();
}
}, AuthenticationUtil.getSystemUserName());
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired() {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
}
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
throw new AlfrescoRuntimeException("Failed to retrieve audit data.", error);
}
public boolean handleAuditEntry(Long entryId, String applicationName, String userName, long time, Map<String, Serializable> values) {
UserInfo userInfo = Node.lookupUserInfo(userName, new HashMap<>(0), personService);
AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
results.add(auditEntry);
return true;
}
};
// resolve the path of the node - note: this will also check read permission for current user
final String nodePath = ISO9075.decode(nodeService.getPath(nodeRef).toPrefixString(namespaceService));
Long fromTime = propertyWalker.getFromTime();
Long toTime = propertyWalker.getToTime();
validateWhereBetween(nodeRef.getId(), fromTime, toTime);
AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() throws Exception {
// QueryParameters
AuditQueryParameters pathParams = new AuditQueryParameters();
// used to orderBY by field createdAt
pathParams.setForward(forward);
pathParams.setUser(propertyWalker.getCreatedByUser());
pathParams.setFromTime(fromTime);
pathParams.setToTime(toTime);
pathParams.setApplicationName(auditApplicationName);
pathParams.addSearchKey("/" + auditAppId + "/transaction/path", nodePath);
auditService.auditQuery(callback, pathParams, limit);
AuditQueryParameters copyFromPathParams = new AuditQueryParameters();
// used to orderBY by field createdAt
copyFromPathParams.setForward(forward);
copyFromPathParams.setUser(propertyWalker.getCreatedByUser());
copyFromPathParams.setFromTime(fromTime);
copyFromPathParams.setToTime(toTime);
copyFromPathParams.setApplicationName(auditApplicationName);
copyFromPathParams.addSearchKey("/" + auditAppId + "/transaction/copy/from/path", nodePath);
auditService.auditQuery(callback, copyFromPathParams, limit);
AuditQueryParameters moveFromPathParams = new AuditQueryParameters();
// used to orderBY by field createdAt
moveFromPathParams.setForward(forward);
moveFromPathParams.setUser(propertyWalker.getCreatedByUser());
moveFromPathParams.setFromTime(fromTime);
moveFromPathParams.setToTime(toTime);
moveFromPathParams.setApplicationName(auditApplicationName);
moveFromPathParams.addSearchKey("/" + auditAppId + "/transaction/move/from/path", nodePath);
auditService.auditQuery(callback, moveFromPathParams, limit);
return null;
}
}, AuthenticationUtil.getSystemUserName());
return results;
}
use of org.alfresco.error.AlfrescoRuntimeException in project alfresco-remote-api by Alfresco.
the class AuditImpl method getQueryResultAuditEntries.
/**
* @param auditAppId
* @param propertyWalker
* @param includeParams
* @param maxItem
* @param forward
* @return
*/
public List<AuditEntry> getQueryResultAuditEntries(AuditService.AuditApplication auditApplication, AuditEntryQueryWalker propertyWalker, List<String> includeParam, int maxItem, Boolean forward) {
final List<AuditEntry> results = new ArrayList<>();
final String auditAppId = auditApplication.getKey().substring(1);
String auditApplicationName = auditApplication.getName();
// Execute the query
AuditQueryParameters params = new AuditQueryParameters();
// used to orderBY by field createdAt
params.setForward(forward);
params.setApplicationName(auditApplicationName);
params.setUser(propertyWalker.getCreatedByUser());
Long fromId = propertyWalker.getFromId();
Long toId = propertyWalker.getToId();
validateWhereBetween(auditAppId, fromId, toId);
Long fromTime = propertyWalker.getFromTime();
Long toTime = propertyWalker.getToTime();
validateWhereBetween(auditAppId, fromTime, toTime);
params.setFromTime(fromTime);
params.setToTime(toTime);
params.setFromId(fromId);
params.setToId(toId);
if (propertyWalker.getValuesKey() != null && propertyWalker.getValuesValue() != null) {
params.addSearchKey(propertyWalker.getValuesKey(), propertyWalker.getValuesValue());
}
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired() {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
}
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
throw new AlfrescoRuntimeException("Failed to retrieve audit data.", error);
}
public boolean handleAuditEntry(Long entryId, String applicationName, String userName, long time, Map<String, Serializable> values) {
UserInfo userInfo = Node.lookupUserInfo(userName, mapUserInfo, personService);
AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
results.add(auditEntry);
return true;
}
};
auditService.auditQuery(callback, params, maxItem);
return results;
}
Aggregations