Search in sources :

Example 76 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.

the class QuickShareRestApiTest method testCopy.

/**
 * This test verifies that copying a shared node does not across the shared aspect and it's associated properties.
 * @throws IOException
 * @throws UnsupportedEncodingException
 * @throws JSONException
 * @throws FileNotFoundException
 * @throws FileExistsException
 */
public void testCopy() throws UnsupportedEncodingException, IOException, JSONException, FileExistsException, FileNotFoundException {
    final int expectedStatusOK = 200;
    String testNodeRef = testNode.toString().replace("://", "/");
    // As user one ...
    // share
    Response rsp = sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", testNodeRef), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
    JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
    String sharedId = jsonRsp.getString("sharedId");
    assertNotNull(sharedId);
    // note: we may have to adjust/remove this check if we change length of id (or it becomes variable length)
    assertEquals(22, sharedId.length());
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
    FileInfo copyFileInfo = fileFolderService.copy(testNode, userOneHome, "Copied node");
    NodeRef copyNodeRef = copyFileInfo.getNodeRef();
    assertFalse(nodeService.hasAspect(copyNodeRef, QuickShareModel.ASPECT_QSHARE));
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) FileInfo(org.alfresco.service.cmr.model.FileInfo)

Example 77 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project alfresco-remote-api by Alfresco.

the class SurfConfigTest method testSurfConfigPermissions.

// MNT-16371
public void testSurfConfigPermissions() throws Exception {
    // Create a site as USER_ONE
    String shortName = UUID.randomUUID().toString();
    JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    assertEquals("myPreset", result.get("sitePreset"));
    assertEquals(shortName, result.get("shortName"));
    assertEquals("myTitle", result.get("title"));
    assertEquals("myDescription", result.get("description"));
    assertEquals(SiteVisibility.PUBLIC.toString(), result.get("visibility"));
    // Make ADMRemoteStore to create the surf-config folder and the dashboard.xml file.
    sendRequest(new PostRequest(URL_ADM + "CREATE/alfresco/site-data/pages/site/" + shortName + "/dashboard.xml?s=sitestore", new JSONObject().toString(), "application/json"), 200);
    // {siteName}/cm:surf-config/
    NodeRef surfConfigFolderRef = nodeService.getChildByName(siteService.getSite(shortName).getNodeRef(), ContentModel.ASSOC_CONTAINS, "surf-config");
    assertEquals("surf-config", nodeService.getProperty(surfConfigFolderRef, ContentModel.PROP_NAME));
    String owner = (String) nodeService.getProperty(surfConfigFolderRef, ContentModel.PROP_OWNER);
    assertFalse(USER_ONE.equalsIgnoreCase(owner));
    assertEquals(AuthenticationUtil.getAdminUserName(), owner);
    assertFalse("Inherit Permissions should be off.", permissionService.getInheritParentPermissions(surfConfigFolderRef));
    Set<AccessPermission> permissions = permissionService.getAllSetPermissions(surfConfigFolderRef);
    assertEquals(1, permissions.size());
    String siteManagerGroup = siteService.getSiteRoleGroup(shortName, SiteModel.SITE_MANAGER);
    AccessPermission accessPermission = permissions.iterator().next();
    assertEquals(siteManagerGroup, accessPermission.getAuthority());
    assertEquals(SiteModel.SITE_MANAGER, accessPermission.getPermission());
    assertTrue(accessPermission.getAccessStatus() == AccessStatus.ALLOWED);
    // This is the method that finally gets called when ALF-21643 steps are followed.
    PagingResults<FileInfo> pageResults = fileFolderService.list(surfConfigFolderRef, true, true, null, null, null, new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE));
    List<FileInfo> fileInfos = pageResults.getPage();
    assertNotNull(fileInfos);
    assertEquals(1, fileInfos.size());
    // {siteName}/cm:surf-config/pages
    assertEquals("pages", fileInfos.get(0).getName());
    // Add USER_TWO as a site collaborator
    JSONObject membership = new JSONObject();
    membership.put("role", SiteModel.SITE_COLLABORATOR);
    JSONObject person = new JSONObject();
    person.put("userName", USER_TWO);
    membership.put("person", person);
    // Post the membership
    Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals(SiteModel.SITE_COLLABORATOR, result.get("role"));
    assertEquals(USER_TWO, result.getJSONObject("authority").get("userName"));
    // Add USER_THREE as a site manager
    membership.put("role", SiteModel.SITE_MANAGER);
    person.put("userName", USER_THREE);
    membership.put("person", person);
    // Post the membership
    response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals(SiteModel.SITE_MANAGER, result.get("role"));
    assertEquals(USER_THREE, result.getJSONObject("authority").get("userName"));
    // USER_TWO is a site collaborator so he should not be able to access the surf-config folder
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
    try {
        fileFolderService.list(surfConfigFolderRef, true, true, null, null, null, new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE));
        fail("USER_TWO dose not have the appropriate permissions to perform this operation.");
    } catch (AccessDeniedException ex) {
    // expected
    }
    // USER_THREE is a site manager so he is able to access the surf-config folder
    AuthenticationUtil.setFullyAuthenticatedUser(USER_THREE);
    pageResults = fileFolderService.list(surfConfigFolderRef, true, true, null, null, null, new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE));
    fileInfos = pageResults.getPage();
    assertNotNull(fileInfos);
    assertEquals(1, fileInfos.size());
    // {siteName}/cm:surf-config/pages
    assertEquals("pages", fileInfos.get(0).getName());
    // Update USER_ONE role from SiteManager to SiteContributor.
    membership.put("role", SiteModel.SITE_CONTRIBUTOR);
    person.put("userName", USER_ONE);
    membership.put("person", person);
    response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
    result = new JSONObject(response.getContentAsString());
    assertEquals(SiteModel.SITE_CONTRIBUTOR, result.get("role"));
    assertEquals(USER_ONE, result.getJSONObject("authority").get("userName"));
    // USER_ONE is no longer a site manager
    // USER_ONE tries to access "{siteName}/cm:surf-config" children
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
    try {
        fileFolderService.list(surfConfigFolderRef, true, true, null, null, null, new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE));
        fail("USER_ONE is not the owner and he is no longer a site manager, so does not have the appropriate permissions to perform this operation");
    } catch (AccessDeniedException ex) {
    // expected
    }
    // USER_ONE tries to access "{siteName}/cm:surf-config/pages" children
    try {
        fileFolderService.list(fileInfos.get(0).getNodeRef(), true, true, null, null, null, new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE));
        fail("USER_ONE is not the owner and he is no longer a site manager, so does not have the appropriate permissions to perform this operation");
    } catch (AccessDeniedException ex) {
    // expected
    }
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) PagingRequest(org.alfresco.query.PagingRequest) Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) FileInfo(org.alfresco.service.cmr.model.FileInfo)

Example 78 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.

the class UnfiledContainerEntityResource method update.

@Override
@WebApiDescription(title = "Update unfiled record container", description = "Updates an unfiled record container with id 'unfiledContainerId'")
public UnfiledContainer update(String unfiledContainerId, UnfiledContainer unfiledContainerInfo, Parameters parameters) {
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("unfiledContainerInfo", unfiledContainerInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, unfiledContainerInfo, parameters);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {

        public FileInfo execute() {
            return fileFolderService.getFileInfo(nodeRef);
        }
    };
    FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
    apiUtils.postActivity(info, unfiledContainerInfo.getParentId(), ActivityType.FILE_UPDATED);
    return nodesModelFactory.createUnfiledContainer(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 79 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.

the class UnfiledRecordFolderChildrenRelation method create.

@Override
@WebApiDescription(title = "Upload file content and meta-data into the repository.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public UnfiledRecordFolderChild create(String unfiledRecordFolderId, FormData formData, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
    mandatory("formData", formData);
    mandatory("parameters", parameters);
    // Retrieve the input data and resolve the parent node
    final UploadInfo uploadInfo = new UploadInfo(formData);
    // Create the record  - returns pair(newNode,parentNode)
    RetryingTransactionCallback<Pair<NodeRef, NodeRef>> callback = new RetryingTransactionCallback<Pair<NodeRef, NodeRef>>() {

        public Pair<NodeRef, NodeRef> execute() {
            final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER, uploadInfo.getRelativePath());
            NodeRef newNode = apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
            return new Pair<NodeRef, NodeRef>(newNode, parentNodeRef);
        }
    };
    Pair<NodeRef, NodeRef> nodeAndParentInfo = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    NodeRef newNode = nodeAndParentInfo.getFirst();
    NodeRef parent = nodeAndParentInfo.getSecond();
    // Get file info for response
    FileInfo info = fileFolderService.getFileInfo(newNode);
    apiUtils.postActivity(info, parent, ActivityType.FILE_ADDED);
    return nodesModelFactory.createUnfiledRecordFolderChild(info, parameters, null, false);
}
Also used : UploadInfo(org.alfresco.rm.rest.api.model.UploadInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) Pair(org.alfresco.util.Pair) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 80 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo in project records-management by Alfresco.

the class UnfiledRecordFolderChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of unfiled container children for the container identified by 'unfiledContainerId'")
public CollectionWithPagingInfo<UnfiledRecordFolderChild> readAll(String unfileRecordFolderId, Parameters parameters) {
    checkNotBlank("unfileRecordFolderId", unfileRecordFolderId);
    mandatory("parameters", parameters);
    String relativePath = parameters.getParameter(Nodes.PARAM_RELATIVE_PATH);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfileRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER, relativePath, true);
    // list unfiled record folders and records
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForUnfiledEndpoint(parameters, LIST_UNFILED_RECORD_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), null, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<UnfiledRecordFolderChild> nodes = new AbstractList<UnfiledRecordFolderChild>() {

        @Override
        public UnfiledRecordFolderChild get(int index) {
            FileInfo info = page.get(index);
            return nodesModelFactory.createUnfiledRecordFolderChild(info, parameters, mapUserInfo, true);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    UnfiledRecordFolder sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createUnfiledRecordFolder(info, parameters, mapUserInfo, true);
    }
    return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : AbstractList(java.util.AbstractList) UnfiledRecordFolder(org.alfresco.rm.rest.api.model.UnfiledRecordFolder) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) UserInfo(org.alfresco.rest.api.model.UserInfo) UnfiledRecordFolderChild(org.alfresco.rm.rest.api.model.UnfiledRecordFolderChild) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Aggregations

FileInfo (org.alfresco.service.cmr.model.FileInfo)101 NodeRef (org.alfresco.service.cmr.repository.NodeRef)82 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)34 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)26 HashMap (java.util.HashMap)20 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)20 QName (org.alfresco.service.namespace.QName)20 AbstractList (java.util.AbstractList)13 UserInfo (org.alfresco.rest.api.model.UserInfo)13 WebApiParam (org.alfresco.rest.framework.WebApiParam)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)10 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)9 IOException (java.io.IOException)8 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)8 Serializable (java.io.Serializable)7 List (java.util.List)7 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)7 FacesContext (javax.faces.context.FacesContext)6