use of org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto 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.StringKeyStringValueDto in project pentaho-platform by pentaho.
the class UnifiedRepositoryToWebServiceAdapter method getFileMetadata.
@Override
public Map<String, Serializable> getFileMetadata(final Serializable fileId) {
final List<StringKeyStringValueDto> fileMetadata = repoWebService.getFileMetadata(fileId.toString());
Assert.notNull(fileMetadata);
final Map<String, Serializable> repoFileMetadata = new HashMap<String, Serializable>(fileMetadata.size());
for (StringKeyStringValueDto entry : fileMetadata) {
repoFileMetadata.put(entry.getKey(), entry.getValue());
}
return repoFileMetadata;
}
use of org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto in project pentaho-platform by pentaho.
the class StringKeyStringValueDtoTest method testInitialization.
@Test
public void testInitialization() {
final StringKeyStringValueDto empty = new StringKeyStringValueDto();
assertNull(empty.getKey());
assertNull(empty.getValue());
assertTrue(empty.equals(new StringKeyStringValueDto()));
assertEquals(empty.hashCode(), new StringKeyStringValueDto().hashCode());
assertFalse(StringUtils.isEmpty(empty.toString()));
final StringKeyStringValueDto sample1 = new StringKeyStringValueDto();
sample1.setKey("test key");
sample1.setValue("test value");
final StringKeyStringValueDto sample2 = new StringKeyStringValueDto("test key", "test value");
assertTrue(sample1.equals(sample2));
assertEquals(sample1.hashCode(), sample2.hashCode());
sample1.setKey(null);
sample2.setKey(null);
assertTrue(sample1.equals(sample2));
assertEquals(sample1.hashCode(), sample2.hashCode());
sample1.setKey(sample1.getValue());
sample1.setValue(null);
sample2.setKey(sample2.getValue());
sample2.setValue(null);
assertTrue(sample1.equals(sample2));
assertEquals(sample1.hashCode(), sample2.hashCode());
sample1.setKey(null);
assertTrue(empty.equals(sample1));
assertEquals(empty.hashCode(), sample1.hashCode());
sample1.setValue("test");
assertFalse(empty.equals(sample1));
assertFalse(empty.equals(sample2));
assertFalse(empty.hashCode() == sample1.hashCode());
assertFalse(empty.hashCode() == sample2.hashCode());
assertFalse(empty.equals(null));
assertFalse(empty.equals(sample1.toString()));
}
use of org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryWebServiceTest method testFileMetadata.
public void testFileMetadata() throws Exception {
final RepositoryFile testfile = repository.createFile(repository.getFile("/etc").getId(), new RepositoryFile.Builder("testfile").build(), new SimpleRepositoryFileData(new ByteArrayInputStream("test".getBytes()), "UTF-8", "text/plain"), null);
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository is setup correctly
assertNotNull(testfile);
assertNotNull(testfile.getId());
final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
assertNotNull(fileMetadata);
assertEquals(0, fileMetadata.size());
}
final List<StringKeyStringValueDto> metadata = new ArrayList<StringKeyStringValueDto>();
metadata.add(new StringKeyStringValueDto("sample key", "sample value"));
metadata.add(new StringKeyStringValueDto("complex key?", "\"an even more 'complex' value\"! {and them some}"));
repositoryWS.setFileMetadata(testfile.getId().toString(), metadata);
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository sees the metadata
assertNotNull(testfile);
assertNotNull(testfile.getId());
final Map<String, Serializable> fileMetadata = repository.getFileMetadata(testfile.getId());
assertNotNull(fileMetadata);
assertEquals(2, fileMetadata.size());
}
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure we can get the same metadata back via the web service
final List<StringKeyStringValueDto> fileMetadata = repositoryWS.getFileMetadata(testfile.getId().toString());
assertNotNull(fileMetadata);
assertEquals(2, fileMetadata.size());
assertTrue(metadata.get(0).equals(fileMetadata.get(0)) || metadata.get(0).equals(fileMetadata.get(1)));
assertTrue(metadata.get(1).equals(fileMetadata.get(0)) || metadata.get(1).equals(fileMetadata.get(1)));
}
}
use of org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto 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());
}
Aggregations