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();
}
}
}
}
}
}
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"?>
* <localePropertiesMapEntries>
* <localeMapDto>
* <locale>default</locale>
* <properties>
* <stringKeyStringValueDto>
* <key>file.title</key>
* <value>myFile</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>jcr:primaryType</key>
* <value>nt:unstructured</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>title</key>
* <value>myFile</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>file.description</key>
* <value>myFile Description</value>
* </stringKeyStringValueDto>
* </properties>
* </localeMapDto>
* </localePropertiesMapEntries>
* </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;
}
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();
}
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;
}
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"?>
* <repositoryFileDto>
* <createdDate>1402911997019</createdDate>
* <fileSize>3461</fileSize>
* <folder>false</folder>
* <hidden>false</hidden>
* <id>ff11ac89-7eda-4c03-aab1-e27f9048fd38</id>
* <lastModifiedDate>1406647160536</lastModifiedDate>
* <locale>en</locale>
* <localePropertiesMapEntries>
* <localeMapDto>
* <locale>default</locale>
* <properties>
* <stringKeyStringValueDto>
* <key>file.title</key>
* <value>myFile</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>jcr:primaryType</key>
* <value>nt:unstructured</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>title</key>
* <value>myFile</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>file.description</key>
* <value>myFile Description</value>
* </stringKeyStringValueDto>
* </properties>
* </localeMapDto>
* </localePropertiesMapEntries>
* <locked>false</locked>
* <name>myFile.prpt</name></name>
* <originalParentFolderPath>/public/admin</originalParentFolderPath>
* <ownerType>-1</ownerType>
* <path>/public/admin/ff11ac89-7eda-4c03-aab1-e27f9048fd38</path>
* <title>myFile</title>
* <versionId>1.9</versionId>
* <versioned>true</versioned>
* </repositoryFileAclDto>
* </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();
}
}
Aggregations