Search in sources :

Example 6 with StringKeyStringValueDto

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

the class FileService method doGetFileLocales.

/**
 * Retrieves the list of locale map for the selected repository file. The list will be empty if a problem occurs.
 *
 * @param pathId colon separated path for the repository file
 * <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @return <code>List<LocaleMapDto></code> the list of locales
 *         <pre function="syntax.xml">
 *           <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 *           &lt;localePropertiesMapEntries&gt;
 *             &lt;localeMapDto&gt;
 *               &lt;locale&gt;default&lt;/locale&gt;
 *               &lt;properties&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;file.title&lt;/key&gt;
 *                   &lt;value&gt;myFile&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;jcr:primaryType&lt;/key&gt;
 *                   &lt;value&gt;nt:unstructured&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;title&lt;/key&gt;
 *                   &lt;value&gt;myFile&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *                 &lt;stringKeyStringValueDto&gt;
 *                   &lt;key&gt;file.description&lt;/key&gt;
 *                   &lt;value&gt;myFile Description&lt;/value&gt;
 *                 &lt;/stringKeyStringValueDto&gt;
 *               &lt;/properties&gt;
 *             &lt;/localeMapDto&gt;
 *           &lt;/localePropertiesMapEntries&gt;
 *         </pre>
 * @throws FileNotFoundException
 */
public List<LocaleMapDto> doGetFileLocales(String pathId) throws FileNotFoundException {
    List<LocaleMapDto> availableLocales = new ArrayList<LocaleMapDto>();
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    if (file == null) {
        throw new FileNotFoundException();
    }
    try {
        List<PentahoLocale> locales = getRepoWs().getAvailableLocalesForFileById(file.getId());
        if (locales != null && !locales.isEmpty()) {
            for (PentahoLocale locale : locales) {
                availableLocales.add(new LocaleMapDto(locale.toString(), null));
            }
        }
    } catch (Exception e) {
        throw new InternalError();
    }
    return availableLocales;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) LocaleMapDto(org.pentaho.platform.repository2.unified.webservices.LocaleMapDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException)

Example 7 with StringKeyStringValueDto

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

the class FileServiceTest method testDoGetLocalProperties.

@Test
public void testDoGetLocalProperties() throws Exception {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String locale = "";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    Set<String> propertiesList = new HashSet<String>();
    propertiesList.add("prop1");
    propertiesList.add("prop2");
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    Properties properties = mock(Properties.class);
    doReturn("value1").when(properties).getProperty("prop1");
    doReturn("value2").when(properties).getProperty("prop2");
    doReturn(false).when(properties).isEmpty();
    doReturn(propertiesList).when(properties).stringPropertyNames();
    PropertiesWrapper propertiesWrapper = mock(PropertiesWrapper.class);
    when(propertiesWrapper.getProperties()).thenReturn(properties);
    doReturn(propertiesWrapper).when(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
    List<StringKeyStringValueDto> keyValueList = fileService.doGetLocaleProperties(pathId, locale);
    verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
    verify(properties).getProperty("prop1");
    verify(properties).getProperty("prop2");
    verify(properties).isEmpty();
    verify(properties).stringPropertyNames();
    verify(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
    assertEquals(2, keyValueList.size());
    assertEquals("prop1", keyValueList.get(1).getKey());
    assertEquals("prop2", keyValueList.get(0).getKey());
    assertEquals("value1", keyValueList.get(1).getValue());
    assertEquals("value2", keyValueList.get(0).getValue());
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with StringKeyStringValueDto

use of org.pentaho.platform.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;
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) Serializable(java.io.Serializable) HashMap(java.util.HashMap)

Example 9 with StringKeyStringValueDto

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

the class FileService method doSetMetadata.

/**
 * Set the metadata on a file
 *
 * @param pathId
 * @param metadata
 * @throws GeneralSecurityException
 */
public void doSetMetadata(String pathId, List<StringKeyStringValueDto> metadata) throws GeneralSecurityException {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    RepositoryFileAclDto fileAcl = getRepoWs().getAcl(file.getId());
    boolean canManage = getSession().getName().equals(fileAcl.getOwner()) || (getPolicy().isAllowed(RepositoryReadAction.NAME) && getPolicy().isAllowed(RepositoryCreateAction.NAME) && getPolicy().isAllowed(AdministerSecurityAction.NAME));
    if (!canManage) {
        if (fileAcl.isEntriesInheriting()) {
            List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAces(file.getId());
            fileAcl.setAces(aces, fileAcl.isEntriesInheriting());
        }
        for (int i = 0; i < fileAcl.getAces().size(); i++) {
            RepositoryFileAclAceDto acl = fileAcl.getAces().get(i);
            if (acl.getRecipient().equals(getSession().getName())) {
                if (acl.getPermissions().contains(RepositoryFilePermission.ACL_MANAGEMENT.ordinal()) || acl.getPermissions().contains(RepositoryFilePermission.ALL.ordinal())) {
                    canManage = true;
                    break;
                }
            }
        }
    }
    if (canManage) {
        Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
        boolean isHidden = RepositoryFile.HIDDEN_BY_DEFAULT;
        boolean isSchedulable = RepositoryFile.SCHEDULABLE_BY_DEFAULT;
        fileMetadata.remove(RepositoryFile.HIDDEN_KEY);
        for (StringKeyStringValueDto nv : metadata) {
            // don't add hidden to the list because it is not actually part of the metadata node
            String key = nv.getKey();
            if (RepositoryFile.HIDDEN_KEY.equalsIgnoreCase(key)) {
                isHidden = BooleanUtils.toBoolean(nv.getValue());
                continue;
            }
            if (RepositoryFile.SCHEDULABLE_KEY.equalsIgnoreCase(key)) {
                isSchedulable = BooleanUtils.toBoolean(nv.getValue());
            }
            fileMetadata.put(key, nv.getValue());
        }
        // now update the rest of the metadata
        if (!file.isFolder()) {
            getRepository().setFileMetadata(file.getId(), fileMetadata);
        }
        // handle hidden flag if it is different
        if (file.isHidden() != isHidden) {
            file.setHidden(isHidden);
            file.setNotSchedulable(!isSchedulable);
            /*
           * Since we cannot simply set the new value, use the RepositoryFileAdapter to create a new instance and then
           * update the original.
           */
            RepositoryFile sourceFile = getRepository().getFileById(file.getId());
            RepositoryFileDto destFileDto = toFileDto(sourceFile, null, false);
            destFileDto.setHidden(isHidden);
            destFileDto.setNotSchedulable(!isSchedulable);
            RepositoryFile destFile = toFile(destFileDto);
            // add the existing acls and file data
            RepositoryFileAcl acl = getRepository().getAcl(sourceFile.getId());
            if (!file.isFolder()) {
                IRepositoryFileData data = RepositoryFileHelper.getFileData(sourceFile);
                getRepository().updateFile(destFile, data, null);
                getRepository().updateAcl(acl);
            } else {
                getRepository().updateFolder(destFile, null);
            }
        }
    } else {
        throw new GeneralSecurityException();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) RepositoryFileAclAceDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 10 with StringKeyStringValueDto

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

the class FileService method doGetMetadata.

/**
 * Get metadata for a file by path id
 *
 * @param pathId
 * @return
 */
public List<StringKeyStringValueDto> doGetMetadata(String pathId) throws FileNotFoundException {
    List<StringKeyStringValueDto> list = null;
    String path = null;
    if (pathId == null || pathId.equals(FileUtils.PATH_SEPARATOR)) {
        path = FileUtils.PATH_SEPARATOR;
    } else {
        if (!pathId.startsWith(FileUtils.PATH_SEPARATOR)) {
            path = idToPath(pathId);
        }
    }
    final RepositoryFileDto file = getRepoWs().getFile(path);
    if (file == null) {
        throw new FileNotFoundException();
    }
    list = getRepoWs().getFileMetadata(file.getId());
    if (list != null) {
        boolean hasSchedulable = false;
        for (StringKeyStringValueDto value : list) {
            if (value.getKey().equals(RepositoryFile.SCHEDULABLE_KEY)) {
                hasSchedulable = true;
                break;
            }
        }
        if (!hasSchedulable) {
            StringKeyStringValueDto schedPerm = new StringKeyStringValueDto(RepositoryFile.SCHEDULABLE_KEY, "true");
            list.add(schedPerm);
        }
        // check file object for hidden value and add it to the list
        list.add(new StringKeyStringValueDto(RepositoryFile.HIDDEN_KEY, String.valueOf(file.isHidden())));
    }
    return list;
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)15 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)11 Test (org.junit.Test)9 FileNotFoundException (java.io.FileNotFoundException)7 GeneralSecurityException (java.security.GeneralSecurityException)7 ArrayList (java.util.ArrayList)7 Matchers.anyString (org.mockito.Matchers.anyString)6 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 IllegalSelectorException (java.nio.channels.IllegalSelectorException)4 InvalidParameterException (java.security.InvalidParameterException)4 Properties (java.util.Properties)4 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)4 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)4 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Response (javax.ws.rs.core.Response)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2