Search in sources :

Example 1 with SiteVisibility

use of org.alfresco.service.cmr.site.SiteVisibility in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method createSiteMembershipRequest.

@Override
public SiteMembershipRequest createSiteMembershipRequest(String inviteeId, final SiteMembershipRequest siteInvite) {
    SiteMembershipRequest request = null;
    inviteeId = people.validatePerson(inviteeId, true);
    // Note that the order of error checking is important. The server first needs to check for the status 404
    // conditions before checking for status 400 conditions. Otherwise the server is open to a probing attack.
    String siteId = siteInvite.getId();
    final SiteInfo siteInfo = sites.validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();
    final SiteVisibility siteVisibility = siteInfo.getVisibility();
    if (siteVisibility.equals(SiteVisibility.PRIVATE)) {
        // note: security, no indication that this is a private site
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    // Is the invitee already a member of the site?
    boolean isMember = siteService.isMember(siteId, inviteeId);
    if (isMember) {
        // yes
        throw new InvalidArgumentException(inviteeId + " is already a member of site " + siteId);
    }
    // Is there an outstanding site invite request for the (invitee, site)?
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation != null) {
        // yes
        throw new InvalidArgumentException(inviteeId + " is already invited to site " + siteId);
    }
    final String inviteeRole = DEFAULT_ROLE;
    String message = siteInvite.getMessage();
    if (message == null) {
        // the invitation service ignores null messages so convert to an empty message.
        message = "";
    }
    if (siteVisibility.equals(SiteVisibility.MODERATED)) {
        request = inviteToModeratedSite(message, inviteeId, siteId, inviteeRole);
    } else if (siteVisibility.equals(SiteVisibility.PUBLIC)) {
        request = inviteToPublicSite(siteInfo, message, inviteeId, inviteeRole);
    } else {
        // note: security, no indication that this is a private site
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    return request;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility)

Example 2 with SiteVisibility

use of org.alfresco.service.cmr.site.SiteVisibility in project alfresco-remote-api by Alfresco.

the class SitesImpl method validateSite.

protected Site validateSite(Site site) {
    // site title - mandatory
    String siteTitle = site.getTitle();
    if ((siteTitle == null) || siteTitle.isEmpty()) {
        throw new InvalidArgumentException("Site title is expected: " + siteTitle);
    } else if (siteTitle.length() > SITE_MAXLEN_TITLE) {
        throw new InvalidArgumentException("Site title exceeds max length of " + SITE_MAXLEN_TITLE + " characters");
    }
    SiteVisibility siteVisibility = site.getVisibility();
    if (siteVisibility == null) {
        throw new InvalidArgumentException("Site visibility is expected: " + siteTitle + " (eg. PUBLIC, PRIVATE, MODERATED)");
    }
    String siteId = site.getId();
    if (siteId == null) {
        // generate a site id from title (similar to Share create site dialog)
        siteId = siteTitle.trim().replaceAll("[^" + SITE_ID_VALID_CHARS_PARTIAL_REGEX + " ]", // remove special characters (except spaces)
        "").replaceAll(" +", // collapse multiple spaces to single space
        " ").replace(" ", // replaces spaces with dashs
        "-").toLowerCase();
    } else {
        if (!siteId.matches("^[" + SITE_ID_VALID_CHARS_PARTIAL_REGEX + "]+")) {
            throw new InvalidArgumentException("Invalid site id - should consist of alphanumeric/dash characters");
        }
    }
    if (siteId.length() > SITE_MAXLEN_ID) {
        throw new InvalidArgumentException("Site id exceeds max length of " + SITE_MAXLEN_ID + " characters");
    }
    site.setId(siteId);
    String siteDescription = site.getDescription();
    if (siteDescription == null) {
        // workaround: to avoid Share error (eg. in My Sites dashlet / freemarker template)
        site.setDescription("");
    }
    if ((siteDescription != null) && (siteDescription.length() > SITE_MAXLEN_DESCRIPTION)) {
        throw new InvalidArgumentException("Site description exceeds max length of " + SITE_MAXLEN_DESCRIPTION + " characters");
    }
    return site;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility)

Example 3 with SiteVisibility

use of org.alfresco.service.cmr.site.SiteVisibility in project alfresco-remote-api by Alfresco.

the class SitesImpl method getFilterPropListOfSites.

private List<FilterProp> getFilterPropListOfSites(final Parameters parameters) {
    List<FilterProp> filterProps = new ArrayList<FilterProp>();
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_SITES_EQUALS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String siteVisibilityStr = propertyWalker.getProperty(PARAM_VISIBILITY, WhereClauseParser.EQUALS, String.class);
        if (siteVisibilityStr != null && !siteVisibilityStr.isEmpty()) {
            SiteVisibility siteVisibility = getSiteVisibilityFromParam(siteVisibilityStr);
            filterProps.add(new FilterPropString(SiteModel.PROP_SITE_VISIBILITY, siteVisibility.name(), FilterPropString.FilterTypeString.EQUALS));
        }
        String sitePreset = propertyWalker.getProperty(PARAM_PRESET, WhereClauseParser.EQUALS, String.class);
        if (sitePreset != null && !sitePreset.isEmpty()) {
            filterProps.add(new FilterPropString(SiteModel.PROP_SITE_PRESET, sitePreset, FilterPropString.FilterTypeString.EQUALS));
        }
    }
    // expected null or non-empty list
    return filterProps.isEmpty() ? null : filterProps;
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) ArrayList(java.util.ArrayList) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 4 with SiteVisibility

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

the class RMSitesImplUnitTest method createRMStandardSite.

@Test
public void createRMStandardSite() 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);
    // call createRMSite method
    RMSite createdRMSite = rmSitesImpl.createRMSite(toCreate, mockedParameters);
    // check siteService.createSite parameters
    ArgumentCaptor<String> sitePresetCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<SiteVisibility> visibilityCaptor = ArgumentCaptor.forClass(SiteVisibility.class);
    ArgumentCaptor<QName> siteTypeCaptor = ArgumentCaptor.forClass(QName.class);
    verify(mockedSiteService, times(1)).createSite(sitePresetCaptor.capture(), idCaptor.capture(), titleCaptor.capture(), descriptionCaptor.capture(), visibilityCaptor.capture(), siteTypeCaptor.capture());
    assertEquals(RM_SITE_PRESET, sitePresetCaptor.getValue());
    assertEquals(RM_SITE_ID, idCaptor.getValue());
    assertEquals(RM_SITE_TITLE, titleCaptor.getValue());
    assertEquals(RM_SITE_DESCRIPTION, descriptionCaptor.getValue());
    assertEquals(SiteVisibility.PUBLIC, visibilityCaptor.getValue());
    assertEquals(RecordsManagementModel.TYPE_RM_SITE, siteTypeCaptor.getValue());
    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, times(1)).addFavourite(any(String.class), any(NodeRef.class));
    // verify returned values for RM site are the right ones
    assertEquals(RMSiteCompliance.STANDARD, createdRMSite.getCompliance());
    assertEquals(null, createdRMSite.getRole());
    assertEquals(RM_SITE_ID, createdRMSite.getId());
    assertEquals(siteNodeRef.getId(), createdRMSite.getGuid());
    assertEquals(RM_SITE_DESCRIPTION, createdRMSite.getDescription());
    assertEquals(RM_SITE_TITLE, createdRMSite.getTitle());
    assertEquals(SiteVisibility.PUBLIC, createdRMSite.getVisibility());
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) QName(org.alfresco.service.namespace.QName) ImporterBinding(org.alfresco.service.cmr.view.ImporterBinding) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RMSite(org.alfresco.rm.rest.api.model.RMSite) 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 SiteVisibility

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

the class RMSitesImplUnitTest method createRMDOD5015Site.

@Test
public void createRMDOD5015Site() throws Exception {
    RMSite toCreate = new RMSite();
    toCreate.setTitle(RM_SITE_TITLE);
    toCreate.setDescription(RM_SITE_DESCRIPTION);
    toCreate.setCompliance(RMSiteCompliance.DOD5015);
    // 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);
    // call createRMSite method
    RMSite createdRMSite = rmSitesImpl.createRMSite(toCreate, mockedParameters);
    // check siteService.createSite parameters
    ArgumentCaptor<String> sitePresetCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<SiteVisibility> visibilityCaptor = ArgumentCaptor.forClass(SiteVisibility.class);
    ArgumentCaptor<QName> siteTypeCaptor = ArgumentCaptor.forClass(QName.class);
    verify(mockedSiteService, times(1)).createSite(sitePresetCaptor.capture(), idCaptor.capture(), titleCaptor.capture(), descriptionCaptor.capture(), visibilityCaptor.capture(), siteTypeCaptor.capture());
    assertEquals(RM_SITE_PRESET, sitePresetCaptor.getValue());
    assertEquals(RM_SITE_ID, idCaptor.getValue());
    assertEquals(RM_SITE_TITLE, titleCaptor.getValue());
    assertEquals(RM_SITE_DESCRIPTION, descriptionCaptor.getValue());
    assertEquals(SiteVisibility.PUBLIC, visibilityCaptor.getValue());
    assertEquals(DOD5015Model.TYPE_DOD_5015_SITE, siteTypeCaptor.getValue());
    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, times(1)).addFavourite(any(String.class), any(NodeRef.class));
    // verify returned values for RM site are the right ones
    assertEquals(RMSiteCompliance.DOD5015, createdRMSite.getCompliance());
    assertEquals(null, createdRMSite.getRole());
    assertEquals(RM_SITE_ID, createdRMSite.getId());
    assertEquals(siteNodeRef.getId(), createdRMSite.getGuid());
    assertEquals(RM_SITE_DESCRIPTION, createdRMSite.getDescription());
    assertEquals(RM_SITE_TITLE, createdRMSite.getTitle());
    assertEquals(SiteVisibility.PUBLIC, createdRMSite.getVisibility());
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) QName(org.alfresco.service.namespace.QName) ImporterBinding(org.alfresco.service.cmr.view.ImporterBinding) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RMSite(org.alfresco.rm.rest.api.model.RMSite) 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)

Aggregations

SiteVisibility (org.alfresco.service.cmr.site.SiteVisibility)5 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)3 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)2 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)2 SiteImportPackageHandler (org.alfresco.rest.api.impl.SiteImportPackageHandler)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 Parameters (org.alfresco.rest.framework.resource.parameters.Parameters)2 RMSite (org.alfresco.rm.rest.api.model.RMSite)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ImporterBinding (org.alfresco.service.cmr.view.ImporterBinding)2 Location (org.alfresco.service.cmr.view.Location)2 QName (org.alfresco.service.namespace.QName)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)1 SiteMembershipRequest (org.alfresco.rest.api.model.SiteMembershipRequest)1 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)1 Query (org.alfresco.rest.framework.resource.parameters.where.Query)1 MapBasedQueryWalkerOrSupported (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported)1 Invitation (org.alfresco.service.cmr.invitation.Invitation)1