Search in sources :

Example 1 with LocaleMapDto

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

the class ZipExportProcessor method createLocales.

/**
 * for each locale stored in in Jcr create a .locale file with the stored node properties
 *
 * @param repositoryFile
 * @param filePath
 * @param isFolder
 * @param outputStream
 * @throws IOException
 */
protected void createLocales(RepositoryFile repositoryFile, String filePath, boolean isFolder, OutputStream outputStream) throws IOException {
    ZipEntry entry;
    String zipEntryName;
    String name;
    String localeName;
    Properties properties;
    ZipOutputStream zos = (ZipOutputStream) outputStream;
    // only process files and folders that we know will have locale settings
    if (supportedLocaleFileExt(repositoryFile)) {
        List<LocaleMapDto> locales = getAvailableLocales(repositoryFile.getId());
        zipEntryName = getFixedZipEntryName(repositoryFile, filePath);
        name = repositoryFile.getName();
        for (LocaleMapDto locale : locales) {
            localeName = locale.getLocale().equalsIgnoreCase("default") ? "" : "_" + locale.getLocale();
            if (isFolder) {
                zipEntryName = getFixedZipEntryName(repositoryFile, filePath) + "index";
                name = "index";
            }
            properties = getUnifiedRepository().getLocalePropertiesForFileById(repositoryFile.getId(), locale.getLocale());
            if (properties != null) {
                // Pentaho Type
                properties.remove("jcr:primaryType");
                try (InputStream is = createLocaleFile(name + localeName, properties, locale.getLocale())) {
                    if (is != null) {
                        entry = new ZipEntry(zipEntryName + localeName + LOCALE_EXT);
                        zos.putNextEntry(entry);
                        IOUtils.copy(is, outputStream);
                        zos.closeEntry();
                    }
                }
            }
        }
    }
}
Also used : LocaleMapDto(org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto) ZipOutputStream(java.util.zip.ZipOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Properties(java.util.Properties)

Example 2 with LocaleMapDto

use of org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto 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.api.repository2.unified.webservices.RepositoryFileDto) LocaleMapDto(org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) 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 3 with LocaleMapDto

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

the class RepositoryFileAdapter method toFile.

public static RepositoryFile toFile(final RepositoryFileDto v) {
    if (v == null) {
        return null;
    }
    RepositoryFile.Builder builder = null;
    if (v.getId() != null) {
        builder = new RepositoryFile.Builder(v.getId(), v.getName());
    } else {
        builder = new RepositoryFile.Builder(v.getName());
    }
    if (v.getOwnerType() != -1) {
        new RepositoryFileSid(v.getOwner(), RepositoryFileSid.Type.values()[v.getOwnerType()]);
    }
    if (v.getLocalePropertiesMapEntries() != null) {
        for (LocaleMapDto localeMapDto : v.getLocalePropertiesMapEntries()) {
            String locale = localeMapDto.getLocale();
            Properties localeProperties = new Properties();
            if (localeMapDto.getProperties() != null) {
                for (StringKeyStringValueDto keyValueDto : localeMapDto.getProperties()) {
                    localeProperties.put(keyValueDto.getKey(), keyValueDto.getValue());
                }
            }
            builder.localeProperties(locale, localeProperties);
        }
    }
    return builder.path(v.getPath()).createdDate(unmarshalDate(v.getCreatedDate())).creatorId(v.getCreatorId()).description(v.getDescription()).folder(v.isFolder()).fileSize(v.getFileSize()).lastModificationDate(unmarshalDate(v.getLastModifiedDate())).locale(v.getLocale()).lockDate(unmarshalDate(v.getLockDate())).locked(v.isLocked()).lockMessage(v.getLockMessage()).lockOwner(v.getLockOwner()).title(v.getTitle()).versioned(v.isVersioned()).versionId(v.getVersionId()).originalParentFolderPath(v.getOriginalParentFolderPath()).deletedDate(unmarshalDate(v.getDeletedDate())).hidden(v.isHidden()).schedulable(!v.isNotSchedulable()).aclNode(v.isAclNode()).build();
}
Also used : StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) LocaleMapDto(org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Properties(java.util.Properties)

Example 4 with LocaleMapDto

use of org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto 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 5 with LocaleMapDto

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

the class FileService method doSetContentCreator.

/**
 * Store content creator of the selected repository file
 *
 * @param pathId colon separated path for the repository file
 * <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @param contentCreator repository file
 * <pre function="syntax.xml">
 *   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 *     &lt;repositoryFileDto&gt;
 *     &lt;createdDate&gt;1402911997019&lt;/createdDate&gt;
 *     &lt;fileSize&gt;3461&lt;/fileSize&gt;
 *     &lt;folder&gt;false&lt;/folder&gt;
 *     &lt;hidden&gt;false&lt;/hidden&gt;
 *     &lt;id&gt;ff11ac89-7eda-4c03-aab1-e27f9048fd38&lt;/id&gt;
 *     &lt;lastModifiedDate&gt;1406647160536&lt;/lastModifiedDate&gt;
 *     &lt;locale&gt;en&lt;/locale&gt;
 *     &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;
 *     &lt;locked&gt;false&lt;/locked&gt;
 *     &lt;name&gt;myFile.prpt&lt;/name&gt;&lt;/name&gt;
 *     &lt;originalParentFolderPath&gt;/public/admin&lt;/originalParentFolderPath&gt;
 *     &lt;ownerType&gt;-1&lt;/ownerType&gt;
 *     &lt;path&gt;/public/admin/ff11ac89-7eda-4c03-aab1-e27f9048fd38&lt;/path&gt;
 *     &lt;title&gt;myFile&lt;/title&gt;
 *     &lt;versionId&gt;1.9&lt;/versionId&gt;
 *     &lt;versioned&gt;true&lt;/versioned&gt;
 *   &lt;/repositoryFileAclDto&gt;
 * </pre>
 * @throws FileNotFoundException
 */
public void doSetContentCreator(String pathId, RepositoryFileDto contentCreator) throws FileNotFoundException {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    if (file == null) {
        throw new FileNotFoundException();
    }
    try {
        Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
        fileMetadata.put(PentahoJcrConstants.PHO_CONTENTCREATOR, contentCreator.getId());
        getRepository().setFileMetadata(file.getId(), fileMetadata);
    } catch (Exception e) {
        throw new InternalError();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) 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)

Aggregations

LocaleMapDto (org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto)6 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 IllegalSelectorException (java.nio.channels.IllegalSelectorException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 InvalidParameterException (java.security.InvalidParameterException)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)3 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)3 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)3 Serializable (java.io.Serializable)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)2 StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)2 PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)2 ExportException (org.pentaho.platform.plugin.services.importexport.ExportException)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Locale (java.util.Locale)1