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;
}
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());
}
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
}
}
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;
}
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();
}
}
Aggregations