use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.
the class AbstractSiteWebScript method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
// Grab the site
String siteName = req.getServiceMatch().getTemplateVars().get("shortname");
SiteInfo site = siteService.getSite(siteName);
if (site == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Site found with that short name");
}
// Process
return executeImpl(site, req, status, cache);
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.
the class InviteServiceTest method testDontOwerrideModeratedSitePermissions.
@Test
public void testDontOwerrideModeratedSitePermissions() throws Exception {
final String MODERATED_SITE_NAME = RandomStringUtils.randomAlphabetic(6);
final String siteManager = RandomStringUtils.randomAlphabetic(6);
final String secondUser = RandomStringUtils.randomAlphabetic(6);
// Create two users
AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() throws Exception {
createPerson(siteManager, siteManager, siteManager, "");
createPerson(secondUser, secondUser, secondUser, "");
return null;
}
}, AuthenticationUtil.getSystemUserName());
// Create moderated site
SiteInfo siteInfo = InviteServiceTest.this.siteService.getSite(MODERATED_SITE_NAME);
if (siteInfo == null) {
siteService.createSite("InviteSitePreset", MODERATED_SITE_NAME, MODERATED_SITE_NAME, MODERATED_SITE_NAME, SiteVisibility.MODERATED);
}
siteService.setMembership(MODERATED_SITE_NAME, siteManager, SiteModel.SITE_MANAGER);
String role = siteService.getMembersRole(MODERATED_SITE_NAME, siteManager);
assertEquals(SiteModel.SITE_MANAGER, role);
// Create request to join to site
String inviteId = createModeratedInvitation(MODERATED_SITE_NAME, "", secondUser, SiteModel.SITE_CONSUMER);
// Set second user to Collaborator
siteService.setMembership(MODERATED_SITE_NAME, secondUser, SiteModel.SITE_COLLABORATOR);
role = siteService.getMembersRole(MODERATED_SITE_NAME, secondUser);
assertEquals(SiteModel.SITE_COLLABORATOR, role);
final String taskId = getTaskId(inviteId);
assertNotNull("Cannot find taskId", taskId);
// Accept invitation
String oldUser = AuthenticationUtil.getFullyAuthenticatedUser();
AuthenticationUtil.setFullyAuthenticatedUser(siteManager);
workflowService.endTask(taskId, "approve");
AuthenticationUtil.setFullyAuthenticatedUser(oldUser);
// Check the role
role = siteService.getMembersRole(MODERATED_SITE_NAME, secondUser);
assertEquals(SiteModel.SITE_COLLABORATOR, role);
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.
the class NodeWebScripTest method tearDown.
@Override
protected void tearDown() throws Exception {
super.tearDown();
// Admin user required to delete users and sites
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
SiteInfo siteInfo = siteService.getSite(TEST_SITE.getShortName());
if (siteInfo != null) {
// Zap the site, and their contents
siteService.deleteSite(TEST_SITE.getShortName());
nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
}
// Delete users
for (String user : new String[] { USER_ONE, USER_TWO, USER_THREE }) {
// Delete the user, as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
if (personService.personExists(user)) {
personService.deletePerson(user);
}
if (this.authenticationService.authenticationExists(user)) {
this.authenticationService.deleteAuthentication(user);
}
}
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.
the class NodeWebScripTest method testLinkCreation.
@SuppressWarnings("unchecked")
public void testLinkCreation() throws Exception {
// Create a folder within the DocLib
NodeRef siteDocLib = siteService.getContainer(TEST_SITE.getShortName(), SiteService.DOCUMENT_LIBRARY);
String testFolder1Name = "testingLinkCreationFolder1";
Map<QName, Serializable> testFolderProps = new HashMap<QName, Serializable>();
testFolderProps.put(ContentModel.PROP_NAME, testFolder1Name);
NodeRef testFolder1 = nodeService.createNode(siteDocLib, ContentModel.ASSOC_CONTAINS, QName.createQName("testingLinkCreationFolder1"), ContentModel.TYPE_FOLDER, testFolderProps).getChildRef();
JSONObject jsonReq = null;
JSONObject json = null;
JSONArray jsonArray = new JSONArray();
JSONArray jsonLinkNodes = null;
JSONObject jsonLinkNode = null;
// Create files in the testFolder1
NodeRef testFile1 = createNode(testFolder1, "testingLinkCreationFile1", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
NodeRef testFile2 = createNode(testFolder1, "testingLinkCreationFile2", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
NodeRef testFile3 = createNode(testFolder1, "testingLinkCreationFile3", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
// Create testFolder2 in the testFolder1
String testFolder2Name = "testingLinkCreationFolder2";
testFolderProps = new HashMap<QName, Serializable>();
testFolderProps.put(ContentModel.PROP_NAME, testFolder2Name);
NodeRef testFolder2 = nodeService.createNode(siteDocLib, ContentModel.ASSOC_CONTAINS, QName.createQName("testingLinkCreationFolder2"), ContentModel.TYPE_FOLDER, testFolderProps).getChildRef();
// Create link to file1 in same folder - testFolder1
Request req = new Request("POST", CREATE_LINK_API + testFile1.getStoreRef().getProtocol() + "/" + testFile1.getStoreRef().getIdentifier() + "/" + testFile1.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray.add(testFile1.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
jsonLinkNodes = (JSONArray) json.get("linkNodes");
assertNotNull(jsonLinkNodes);
assertEquals(1, jsonLinkNodes.size());
assertEquals("true", json.get("overallSuccess"));
assertEquals("1", json.get("successCount"));
assertEquals("0", json.get("failureCount"));
jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
String nodeRef = (String) jsonLinkNode.get("nodeRef");
NodeRef file1Link = new NodeRef(nodeRef);
// Check that app:linked aspect is added on sourceNode
assertEquals(true, nodeService.hasAspect(testFile1, ApplicationModel.ASPECT_LINKED));
assertEquals(true, nodeService.exists(file1Link));
nodeService.deleteNode(file1Link);
assertEquals(false, nodeService.hasAspect(testFile1, ApplicationModel.ASPECT_LINKED));
// Create link to testFolder2 in same folder (testFolder1)
req = new Request("POST", CREATE_LINK_API + testFolder2.getStoreRef().getProtocol() + "/" + testFolder2.getStoreRef().getIdentifier() + "/" + testFolder2.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(testFolder2.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
jsonLinkNodes = (JSONArray) json.get("linkNodes");
assertNotNull(jsonLinkNodes);
assertEquals(1, jsonLinkNodes.size());
assertEquals("true", json.get("overallSuccess"));
assertEquals("1", json.get("successCount"));
assertEquals("0", json.get("failureCount"));
jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
nodeRef = (String) jsonLinkNode.get("nodeRef");
NodeRef folder2Link = new NodeRef(nodeRef);
assertEquals(true, nodeService.hasAspect(testFolder2, ApplicationModel.ASPECT_LINKED));
assertEquals(true, nodeService.exists(folder2Link));
// create another link of testFolder2 in siteDocLib
req = new Request("POST", CREATE_LINK_API + testFolder2.getStoreRef().getProtocol() + "/" + testFolder2.getStoreRef().getIdentifier() + "/" + testFolder2.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, siteDocLib.toString());
jsonArray = new JSONArray();
jsonArray.add(testFolder2.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
jsonLinkNodes = (JSONArray) json.get("linkNodes");
assertNotNull(jsonLinkNodes);
assertEquals(1, jsonLinkNodes.size());
assertEquals("true", json.get("overallSuccess"));
assertEquals("1", json.get("successCount"));
assertEquals("0", json.get("failureCount"));
jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
nodeRef = (String) jsonLinkNode.get("nodeRef");
NodeRef folder2Link2 = new NodeRef(nodeRef);
// delete folder2Link and check that aspect exists since we have another
// link for testFolder2
nodeService.deleteNode(folder2Link);
assertEquals(true, nodeService.hasAspect(testFolder2, ApplicationModel.ASPECT_LINKED));
nodeService.deleteNode(folder2Link2);
assertEquals(false, nodeService.hasAspect(testFolder2, ApplicationModel.ASPECT_LINKED));
// Create link to testFile1, testFile2 and testFile3 in same testFolder1
req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(testFile1.toString());
jsonArray.add(testFile2.toString());
jsonArray.add(testFile3.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
jsonLinkNodes = (JSONArray) json.get("linkNodes");
assertNotNull(jsonLinkNodes);
assertEquals(3, jsonLinkNodes.size());
assertEquals("true", json.get("overallSuccess"));
assertEquals("3", json.get("successCount"));
assertEquals("0", json.get("failureCount"));
NodeRef fileLink = null;
List<NodeRef> fileLinks = new ArrayList<NodeRef>();
for (int i = 0; i < jsonLinkNodes.size(); i++) {
jsonLinkNode = (JSONObject) jsonLinkNodes.get(i);
nodeRef = (String) jsonLinkNode.get("nodeRef");
fileLink = new NodeRef(nodeRef);
fileLinks.add(fileLink);
assertEquals(true, nodeService.exists(fileLink));
}
// try to create another link in the same location - an exception should be thrown
req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(testFile1.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_BAD_REQUEST));
// delete all 3 files and check that the links are deleted too
nodeService.deleteNode(testFile1);
nodeService.deleteNode(testFile2);
nodeService.deleteNode(testFile3);
for (NodeRef linkNodeRef : fileLinks) {
assertEquals(false, nodeService.exists(linkNodeRef));
}
// try create a link to a site - shouldn't be possible
SiteInfo site2 = createSite("Site2TestingNodeCreateLink");
NodeRef siteNodeRef = site2.getNodeRef();
req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(siteNodeRef.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_BAD_REQUEST));
// create a file and a link to that file inside the documentLibrary
NodeRef site2DocLib = siteService.getContainer(TEST_SITE.getShortName(), SiteService.DOCUMENT_LIBRARY);
NodeRef testFileSite2 = createNode(site2DocLib, "testingLinkCreationFileInSite2", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, site2DocLib.toString());
jsonArray = new JSONArray();
jsonArray.add(testFileSite2.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
// links are created with success, try to delete site2 - should succeed
siteService.deleteSite(site2.getShortName());
nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteNodeRef));
// Links can be created in Shared Files, My Files and Repository
NodeRef testFile4 = createNode(testFolder1, "testingLinkCreationFile4", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://company/shared");
jsonArray = new JSONArray();
jsonArray.add(testFile4.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://user/home");
jsonArray = new JSONArray();
jsonArray.add(testFile4.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
// create link in Repository as Admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://company/home");
jsonArray = new JSONArray();
jsonArray.add(testFile4.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
// all 3 links are created with success, delete all links
req = new Request("DELETE", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId() + "/delete");
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
// all links are removed with success marker aspect should be removed too
assertEquals(false, nodeService.hasAspect(testFile4, ApplicationModel.ASPECT_LINKED));
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
// you should not be able to create links for locked nodes but you can delete links
final NodeRef testFile5 = createNode(testFolder1, "testingLinkCreationFileWithLock", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
req = new Request("POST", CREATE_LINK_API + testFile5.getStoreRef().getProtocol() + "/" + testFile5.getStoreRef().getIdentifier() + "/" + testFile5.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(testFile5.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
jsonLinkNodes = (JSONArray) json.get("linkNodes");
assertNotNull(jsonLinkNodes);
assertEquals(1, jsonLinkNodes.size());
assertEquals("true", json.get("overallSuccess"));
assertEquals("1", json.get("successCount"));
assertEquals("0", json.get("failureCount"));
jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
nodeRef = (String) jsonLinkNode.get("nodeRef");
NodeRef file5Link = new NodeRef(nodeRef);
assertEquals(true, nodeService.hasAspect(testFile5, ApplicationModel.ASPECT_LINKED));
assertEquals(true, nodeService.exists(file5Link));
// checkout the node testFile5
final NodeRef workingCopy = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Exception {
return checkOutCheckInService.checkout(testFile5);
}
});
assertNotNull(workingCopy);
// try to create link for working copy
req = new Request("POST", CREATE_LINK_API + workingCopy.getStoreRef().getProtocol() + "/" + workingCopy.getStoreRef().getIdentifier() + "/" + workingCopy.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
jsonArray = new JSONArray();
jsonArray.add(workingCopy.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
// should fail since source node is working copy
json = asJSON(sendRequest(req, Status.STATUS_BAD_REQUEST));
// delete the link when source node is locked
nodeService.deleteNode(file5Link);
assertEquals(false, nodeService.hasAspect(testFile5, ApplicationModel.ASPECT_LINKED));
// release the lock
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() {
public Object execute() throws Exception {
checkOutCheckInService.checkin(workingCopy, new HashMap<String, Serializable>());
return null;
}
});
assertEquals(false, nodeService.hasAspect(testFile5, ContentModel.ASPECT_LOCKABLE));
// test that Consumers can create and delete links if they have only read permission
NodeRef testFile6 = createNode(testFolder1, "testingLinkCreationFile6", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
assertTrue(permissionService.hasPermission(testFile6, PermissionService.READ) == AccessStatus.ALLOWED);
assertTrue(permissionService.hasPermission(testFile6, PermissionService.WRITE) == AccessStatus.DENIED);
// create another link of testFile1 in MyFiles
req = new Request("POST", CREATE_LINK_API + testFile6.getStoreRef().getProtocol() + "/" + testFile6.getStoreRef().getIdentifier() + "/" + testFile6.getId());
jsonReq = new JSONObject();
jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://user/home");
jsonArray = new JSONArray();
jsonArray.add(testFile6.toString());
jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
req.setBody(jsonReq.toString().getBytes());
req.setType(MimetypeMap.MIMETYPE_JSON);
json = asJSON(sendRequest(req, Status.STATUS_OK));
jsonLinkNodes = (JSONArray) json.get("linkNodes");
assertNotNull(jsonLinkNodes);
assertEquals(1, jsonLinkNodes.size());
assertEquals("true", json.get("overallSuccess"));
assertEquals("1", json.get("successCount"));
assertEquals("0", json.get("failureCount"));
jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
nodeRef = (String) jsonLinkNode.get("nodeRef");
NodeRef testFileSite3Link = new NodeRef(nodeRef);
nodeService.exists(testFileSite3Link);
assertEquals(true, nodeService.hasAspect(testFile6, ApplicationModel.ASPECT_LINKED));
}
use of org.alfresco.service.cmr.site.SiteInfo 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();
}
Aggregations