Search in sources :

Example 31 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.

the class RepositoryFileAdapter method toFileDto.

public static RepositoryFileDto toFileDto(final RepositoryFile v, Set<String> memberSet, boolean exclude, boolean includeAcls) {
    if (v == null) {
        return null;
    }
    RepositoryFileDto f = new RepositoryFileDto();
    // no longer exists, so it returns null
    try {
        if (include("name", memberSet, exclude)) {
            f.setName(v.getName());
        }
        if (include("path", memberSet, exclude)) {
            f.setPath(v.getPath());
        }
        if (include("hidden", memberSet, exclude)) {
            f.setHidden(v.isHidden());
        }
        if (include("aclNode", memberSet, exclude)) {
            f.setAclNode(v.isAclNode());
        }
        if (include("createDate", memberSet, exclude)) {
            f.setCreatedDate(marshalDate(v.getCreatedDate()));
        }
        if (include("creatorId", memberSet, exclude)) {
            f.setCreatorId(v.getCreatorId());
        }
        if (include("fileSize", memberSet, exclude)) {
            f.setFileSize(v.getFileSize());
        }
        if (include("description", memberSet, exclude)) {
            f.setDescription(v.getDescription());
        }
        if (include("folder", memberSet, exclude)) {
            f.setFolder(v.isFolder());
        }
        // it must be present or the tree rest service call will error
        if (v.getId() != null) {
            f.setId(v.getId().toString());
        }
        if (include("lastModifiedDate", memberSet, exclude)) {
            f.setLastModifiedDate(marshalDate(v.getLastModifiedDate()));
        }
        if (include("locale", memberSet, exclude)) {
            f.setLocale(v.getLocale());
        }
        if (include("originalParentFolderPath", memberSet, exclude)) {
            f.setOriginalParentFolderPath(v.getOriginalParentFolderPath());
        }
        if (include("deletedDate", memberSet, exclude)) {
            f.setDeletedDate(marshalDate(v.getDeletedDate()));
        }
        if (include("lockDate", memberSet, exclude)) {
            f.setLockDate(marshalDate(v.getLockDate()));
        }
        if (include("locked", memberSet, exclude)) {
            f.setLocked(v.isLocked());
        }
        if (include("lockMessage", memberSet, exclude)) {
            f.setLockMessage(v.getLockMessage());
        }
        if (include("lockOwner", memberSet, exclude)) {
            f.setLockOwner(v.getLockOwner());
        }
        if (include("title", memberSet, exclude)) {
            f.setTitle(v.getTitle());
        }
        if (include("versioned", memberSet, exclude)) {
            f.setVersioned(v.isVersioned());
        }
        if (include("versionId", memberSet, exclude)) {
            if (v.getVersionId() != null) {
                f.setVersionId(v.getVersionId().toString());
            }
        }
    } catch (NullPointerException e) {
        getLogger().warn("NullPointerException while reading file attributes, returning null. Probable cause: File does not" + "exist anymore: ");
        return null;
    }
    if (includeAcls) {
        if (v.getId() != null) {
            try {
                String id = v.getId().toString();
                f.setRepositoryFileAclDto(getRepoWs().getAcl(id));
                if (f.getRepositoryFileAclDto().isEntriesInheriting()) {
                    List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAces(id);
                    f.getRepositoryFileAclDto().setAces(aces, f.getRepositoryFileAclDto().isEntriesInheriting());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (include("owner", memberSet, exclude)) {
            Serializable id = v.getId();
            if (id != null) {
                RepositoryFileAclDto acl = getRepoWs().getAcl("" + id);
                if (acl != null) {
                    f.setOwner(acl.getOwner());
                }
            }
        }
    }
    if (include("locales", memberSet, exclude)) {
        if (v.getLocalePropertiesMap() != null) {
            f.setLocalePropertiesMapEntries(new ArrayList<LocaleMapDto>());
            for (Map.Entry<String, Properties> entry : v.getLocalePropertiesMap().entrySet()) {
                LocaleMapDto localeMapDto = new LocaleMapDto();
                List<StringKeyStringValueDto> valuesDto = new ArrayList<StringKeyStringValueDto>();
                Properties properties = entry.getValue();
                if (properties != null) {
                    for (String propertyName : properties.stringPropertyNames()) {
                        valuesDto.add(new StringKeyStringValueDto(propertyName, properties.getProperty(propertyName)));
                    }
                }
                localeMapDto.setLocale(entry.getKey());
                localeMapDto.setProperties(valuesDto);
                f.getLocalePropertiesMapEntries().add(localeMapDto);
            }
        }
    }
    IRepositoryVersionManager repositoryVersionManager;
    try {
        repositoryVersionManager = JcrRepositoryFileUtils.getRepositoryVersionManager();
        // Not found, must be in Spoon
        if (repositoryVersionManager == null) {
            return f;
        }
    } catch (NoClassDefFoundError ex) {
        // support tree and child calls.
        return f;
    }
    if (include("versioningEnabled", memberSet, exclude)) {
        f.setVersioningEnabled(repositoryVersionManager.isVersioningEnabled(v.getPath()));
    }
    if (include("versionCommentEnabled", memberSet, exclude)) {
        f.setVersionCommentEnabled(repositoryVersionManager.isVersionCommentEnabled(v.getPath()));
    }
    return f;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) Serializable(java.io.Serializable) LocaleMapDto(org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList) Properties(java.util.Properties) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) Map(java.util.Map)

Example 32 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.

the class FileServiceTest method doSetMetadataException.

@Test
public void doSetMetadataException() {
    String pathId = "path:to:file:file1.ext";
    List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
    doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
    doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    RepositoryFileAclDto repositoryFileAclDto = mock(RepositoryFileAclDto.class);
    doReturn("sessionName").when(repositoryFileAclDto).getOwner();
    doReturn(repositoryFileAclDto).when(fileService.defaultUnifiedRepositoryWebService).getAcl(anyString());
    IPentahoSession pentahoSession = mock(IPentahoSession.class);
    doReturn(pentahoSession).when(fileService).getSession();
    doReturn("sessionName1").when(pentahoSession).getName();
    try {
        fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
        fail();
    } catch (GeneralSecurityException e) {
    // Should catch the exception
    }
    verify(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    verify(fileService.defaultUnifiedRepositoryWebService).getAcl(anyString());
    verify(repositoryFileAclDto).getOwner();
    verify(fileService.policy).isAllowed(anyString());
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 33 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.

the class FileServiceTest method testSetFileAclsException.

@Test
public void testSetFileAclsException() throws Exception {
    String pathId = "/usr/folder/file.txt";
    RepositoryFileAclDto acl = mock(RepositoryFileAclDto.class);
    try {
        fileService.setFileAcls(pathId, acl);
        fail();
    } catch (FileNotFoundException e) {
    // expected exception
    }
}
Also used : RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 34 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class DataSourcePublishIT method generateACL.

private RepositoryFileAclDto generateACL(String userOrRole, RepositoryFileSid.Type type) {
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    aclDto.setOwner(singleTenantAdminUserName);
    aclDto.setEntriesInheriting(false);
    final ArrayList<RepositoryFileAclAceDto> aces = new ArrayList<RepositoryFileAclAceDto>();
    final RepositoryFileAclAceDto aceDto = new RepositoryFileAclAceDto();
    aceDto.setRecipient(userOrRole);
    aceDto.setRecipientType(type.ordinal());
    final ArrayList<Integer> permissions = new ArrayList<Integer>();
    permissions.add(RepositoryFilePermission.ALL.ordinal());
    aceDto.setPermissions(permissions);
    aces.add(aceDto);
    aclDto.setAces(aces);
    return aclDto;
}
Also used : RepositoryFileAclAceDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList)

Example 35 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class MetadataService method setMetadataAcl.

public void setMetadataAcl(String domainId, RepositoryFileAclDto aclDto) throws PentahoAccessControlException, FileNotFoundException {
    checkMetadataExists(domainId);
    if (aclAwarePentahoMetadataDomainRepositoryImporter != null) {
        final RepositoryFileAcl acl = aclDto == null ? null : repositoryFileAclAdapter.unmarshal(aclDto);
        aclAwarePentahoMetadataDomainRepositoryImporter.setAclFor(domainId, acl);
        flushDataSources();
    }
}
Also used : RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Aggregations

Test (org.junit.Test)41 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)26 RepositoryFileAclDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto)20 Matchers.anyString (org.mockito.Matchers.anyString)16 InputStream (java.io.InputStream)14 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)13 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)11 RepositoryFileAclAceDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto)11 FileInputStream (java.io.FileInputStream)9 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)9 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)9 ArrayList (java.util.ArrayList)8 RepositoryFileAclAdapter (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileNotFoundException (java.io.FileNotFoundException)7 Serializable (java.io.Serializable)7 GeneralSecurityException (java.security.GeneralSecurityException)6 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4