Search in sources :

Example 1 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project records-management by Alfresco.

the class BootstrapTestDataGet method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    // resolve import argument
    boolean importData = false;
    if (req.getParameter(ARG_IMPORT) != null) {
        importData = Boolean.parseBoolean(req.getParameter(ARG_IMPORT));
    }
    // resolve rm site
    String siteName = RmSiteType.DEFAULT_SITE_NAME;
    if (req.getParameter(ARG_SITE_NAME) != null) {
        siteName = req.getParameter(ARG_SITE_NAME);
    }
    if (importData) {
        SiteInfo site = siteService.getSite(siteName);
        if (site == null) {
            throw new AlfrescoRuntimeException("Records Management site does not exist: " + siteName);
        }
        // resolve documentLibrary (filePlan) container
        NodeRef filePlan = siteService.getContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY);
        if (filePlan == null) {
            filePlan = siteService.createContainer(siteName, RmSiteType.COMPONENT_DOCUMENT_LIBRARY, TYPE_FILE_PLAN, null);
        }
        // import the RM test data ACP into the the provided filePlan node reference
        InputStream is = BootstrapTestDataGet.class.getClassLoader().getResourceAsStream(XML_IMPORT);
        if (is == null) {
            throw new AlfrescoRuntimeException("The DODExampleFilePlan.xml import file could not be found");
        }
        Reader viewReader = null;
        try {
            viewReader = new InputStreamReader(is, CHARSET_NAME);
        } catch (UnsupportedEncodingException error) {
            throw new AlfrescoRuntimeException("The Character Encoding '" + CHARSET_NAME + "' is not supported.", error);
        }
        Location location = new Location(filePlan);
        importerService.importView(viewReader, location, null, null);
    }
    // Patch data
    BootstrapTestDataGet.patchLoadedData(searchService, nodeService, recordsManagementService, recordsManagementActionService, permissionService, authorityService, recordsManagementSecurityService, recordsManagementSearchBehaviour, dispositionService, recordFolderService);
    Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
    model.put("success", true);
    return model;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Location(org.alfresco.service.cmr.view.Location)

Example 2 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project records-management by Alfresco.

the class InplaceRecordServiceImpl method moveRecord.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.record.InplaceRecordService#moveRecord(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public void moveRecord(final NodeRef nodeRef, final NodeRef targetNodeRef) {
    ParameterCheck.mandatory("nodeRef", nodeRef);
    ParameterCheck.mandatory("targetNodeRef", targetNodeRef);
    NodeRef sourceParentNodeRef = null;
    NodeRef originatingLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_RECORD_ORIGINATING_LOCATION);
    for (ChildAssociationRef parentAssoc : nodeService.getParentAssocs(nodeRef)) {
        if (!parentAssoc.isPrimary() && parentAssoc.getParentRef().equals(originatingLocation)) {
            sourceParentNodeRef = parentAssoc.getParentRef();
            break;
        }
    }
    if (sourceParentNodeRef == null) {
        throw new AlfrescoRuntimeException("Could not find source parent node reference.");
    }
    SiteInfo sourceSite = siteService.getSite(sourceParentNodeRef);
    SiteInfo targetSite = siteService.getSite(targetNodeRef);
    if (!sourceSite.equals(targetSite)) {
        throw new AlfrescoRuntimeException("The record can only be moved within the same collaboration site.");
    }
    if (!sourceSite.getSitePreset().equals("site-dashboard")) {
        throw new AlfrescoRuntimeException("Only records within a collaboration site can be moved.");
    }
    final NodeRef source = sourceParentNodeRef;
    authenticationUtil.runAsSystem(new RunAsWork<Void>() {

        @Override
        public Void doWork() {
            try {
                // Move the record
                fileFolderService.moveFrom(nodeRef, source, targetNodeRef, null);
                // Update the originating location property
                nodeService.setProperty(nodeRef, PROP_RECORD_ORIGINATING_LOCATION, targetNodeRef);
            } catch (FileExistsException | FileNotFoundException ex) {
                throw new AlfrescoRuntimeException("Can't move node: " + ex);
            }
            return null;
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 3 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project records-management by Alfresco.

the class RmSiteType method beforeDeleteNode.

/**
 * @see org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy#beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef)
 */
@Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT)
public void beforeDeleteNode(NodeRef nodeRef) {
    final SiteInfo siteInfo = siteService.getSite(nodeRef);
    if (siteInfo != null) {
        // grab the file plan for the RM site
        NodeRef filePlan = AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {

            @Override
            public NodeRef doWork() {
                return siteService.getContainer(siteInfo.getShortName(), COMPONENT_DOCUMENT_LIBRARY);
            }
        });
        if (filePlan != null) {
            // determine whether the current user has delete capability on the file plan node
            AccessStatus accessStatus = capabilityService.getCapabilityAccessState(filePlan, "Delete");
            if (AccessStatus.DENIED.equals(accessStatus)) {
                throw new AlfrescoRuntimeException("The records management site can not be deleted, because the user doesn't have sufficient privillages to delete the file plan.");
            }
            // work around for MNT-11038 .. we want to ensure that the RM site can be created once it's been deleted since we only
            // allow one short name for the RM site
            AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

                @Override
                public Void doWork() {
                    // delete the authority
                    String siteGroup = siteService.getSiteGroup(siteInfo.getShortName());
                    authorityService.deleteAuthority(siteGroup, true);
                    return null;
                }
            });
            filePlanType.disable();
        }
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AccessStatus(org.alfresco.service.cmr.security.AccessStatus) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 4 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project records-management by Alfresco.

the class RMSitesImplUnitTest method createRMSiteWithSkipAddToFavouritesParameter.

@Test
public void createRMSiteWithSkipAddToFavouritesParameter() throws Exception {
    RMSite toCreate = new RMSite();
    toCreate.setTitle(RM_SITE_TITLE);
    toCreate.setDescription(RM_SITE_DESCRIPTION);
    // mocked SiteInfo
    SiteInfo mockedSiteInfo = mock(SiteInfo.class);
    NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
    when(mockedSiteInfo.getShortName()).thenReturn(RM_SITE_ID);
    when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
    when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
    when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
    when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
    when(mockedSiteService.createSite(any(String.class), any(String.class), any(String.class), any(String.class), any(SiteVisibility.class), any(QName.class))).thenReturn(mockedSiteInfo);
    // mock Parameters
    Parameters mockedParameters = mock(Parameters.class);
    when(mockedParameters.getParameter(PARAM_SKIP_ADDTOFAVORITES)).thenReturn(Boolean.toString(true));
    // call createRMSite method
    rmSitesImpl.createRMSite(toCreate, mockedParameters);
    verify(mockedSiteService, times(1)).createSite(RM_SITE_PRESET, RM_SITE_ID, RM_SITE_TITLE, RM_SITE_DESCRIPTION, SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE);
    verify(mockedImporterService, times(1)).importView(any(SiteImportPackageHandler.class), any(Location.class), any(ImporterBinding.class), eq(null));
    verify(mockedSiteService, times(1)).createContainer(RM_SITE_ID, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
    verify(mockedFavouritesService, never()).addFavourite(any(String.class), any(NodeRef.class));
}
Also used : ImporterBinding(org.alfresco.service.cmr.view.ImporterBinding) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RMSite(org.alfresco.rm.rest.api.model.RMSite) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) QName(org.alfresco.service.namespace.QName) SiteImportPackageHandler(org.alfresco.rest.api.impl.SiteImportPackageHandler) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility) Location(org.alfresco.service.cmr.view.Location) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Example 5 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project records-management by Alfresco.

the class RMSitesImplUnitTest method getRMSite.

@Test
public void getRMSite() throws Exception {
    String siteId = RM_SITE_ID;
    SiteInfo mockedSiteInfo = mock(SiteInfo.class);
    NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
    when(mockedSiteInfo.getShortName()).thenReturn(siteId);
    when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
    when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
    when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
    when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
    when(mockedNodeService.getType(siteNodeRef)).thenReturn(RecordsManagementModel.TYPE_RM_SITE);
    when(mockedSiteService.getSite(siteId)).thenReturn(mockedSiteInfo);
    when(mockedSiteService.getMembersRole(eq(siteId), any(String.class))).thenReturn(RM_SITE_MANAGER_ROLE);
    // STANDARD compliance
    RMSite rmSite = rmSitesImpl.getRMSite(siteId);
    assertEquals(RMSiteCompliance.STANDARD, rmSite.getCompliance());
    assertEquals(RM_SITE_MANAGER_ROLE, rmSite.getRole());
    assertEquals(siteId, rmSite.getId());
    assertEquals(siteNodeRef.getId(), rmSite.getGuid());
    assertEquals(RM_SITE_DESCRIPTION, rmSite.getDescription());
    assertEquals(RM_SITE_TITLE, rmSite.getTitle());
    assertEquals(SiteVisibility.PUBLIC, rmSite.getVisibility());
    // DOD5015 compliance
    when(mockedNodeService.getType(siteNodeRef)).thenReturn(DOD5015Model.TYPE_DOD_5015_SITE);
    rmSite = rmSitesImpl.getRMSite(siteId);
    assertEquals(RMSiteCompliance.DOD5015, rmSite.getCompliance());
    assertEquals(RM_SITE_MANAGER_ROLE, rmSite.getRole());
    assertEquals(siteId, rmSite.getId());
    assertEquals(siteNodeRef.getId(), rmSite.getGuid());
    assertEquals(RM_SITE_DESCRIPTION, rmSite.getDescription());
    assertEquals(RM_SITE_TITLE, rmSite.getTitle());
    assertEquals(SiteVisibility.PUBLIC, rmSite.getVisibility());
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RMSite(org.alfresco.rm.rest.api.model.RMSite) BaseUnitTest(org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest) Test(org.junit.Test)

Aggregations

SiteInfo (org.alfresco.service.cmr.site.SiteInfo)105 NodeRef (org.alfresco.service.cmr.repository.NodeRef)43 ArrayList (java.util.ArrayList)22 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)18 Test (org.junit.Test)18 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)17 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)16 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)15 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)15 QName (org.alfresco.service.namespace.QName)14 HashMap (java.util.HashMap)13 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)13 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)12 Serializable (java.io.Serializable)9 IOException (java.io.IOException)8 JSONObject (org.json.simple.JSONObject)8 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)6 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)6 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)6