use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileService method doGetContentCreator.
/**
* Gets the content creator of the specified file
*
* @param pathId
* @return
*/
public RepositoryFileDto doGetContentCreator(String pathId) throws FileNotFoundException {
RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
if (file == null) {
throw new FileNotFoundException();
}
Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
String creatorId = (String) fileMetadata.get(PentahoJcrConstants.PHO_CONTENTCREATOR);
if (creatorId != null && creatorId.length() > 0) {
return getRepoWs().getFileById(creatorId);
}
return null;
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileService method setFileAcls.
/**
* Save the acls of the selected file to the repository
*
* This method is used to update and save the acls of the selected file to the repository
*
* @param pathId @param pathId colon separated path for the repository file
* <pre function="syntax.xml">
* :path:to:file:id
* </pre>
* @param acl Acl of the repository file <code> RepositoryFileAclDto </code>
* @throws FileNotFoundException
*/
public void setFileAcls(String pathId, RepositoryFileAclDto acl) throws FileNotFoundException {
RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
if (file == null) {
// file does not exist or is not readable but we can't tell at this point
throw new FileNotFoundException();
}
acl.setId(file.getId());
// here we remove fake admin role added for display purpose only
List<RepositoryFileAclAceDto> aces = acl.getAces();
if (aces != null) {
Iterator<RepositoryFileAclAceDto> it = aces.iterator();
while (it.hasNext()) {
RepositoryFileAclAceDto ace = it.next();
if (!ace.isModifiable()) {
it.remove();
}
}
}
getRepoWs().updateAcl(acl);
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto 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.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileService method searchGeneratedContent.
/**
* @param userDir the user home directory
* @param targetComparator the comparator to filter
* @param metadataConstant the property used to get the file property to compare
* @return list of <code> repositoryFileDto </code>
* @throws FileNotFoundException
* @private
*/
protected List<RepositoryFileDto> searchGeneratedContent(String userDir, String targetComparator, String metadataConstant) throws FileNotFoundException {
List<RepositoryFileDto> content = new ArrayList<RepositoryFileDto>();
RepositoryFile workspaceFolder = getRepository().getFile(userDir);
if (workspaceFolder != null) {
List<RepositoryFile> children = getRepository().getChildren(workspaceFolder.getId());
for (RepositoryFile child : children) {
if (!child.isFolder()) {
Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(child.getId());
String creatorId = (String) fileMetadata.get(metadataConstant);
if (creatorId != null && creatorId.equals(targetComparator)) {
content.add(toFileDto(child, null, false));
}
}
}
} else {
logger.error(Messages.getInstance().getString("FileResource.WORKSPACE_FOLDER_NOT_FOUND", userDir));
throw new FileNotFoundException(userDir);
}
return content;
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileService method canRestoreToFolderWithNoConflicts.
/**
* @param params
* id of files, separated by ','
*
* @return false if homeFolder has files
* with names and extension equal to passed files
* true otherwise
*
* @throws IllegalArgumentException
* if {@code params} is null
*/
public boolean canRestoreToFolderWithNoConflicts(String pathToFolder, String params) {
if (params == null) {
throw new IllegalArgumentException("parameters cannot be null");
}
List<RepositoryFileDto> filesInFolder = doGetChildren(pathToFolder, null, false, true);
String[] sourceFileIds = FileUtils.convertCommaSeparatedStringToArray(params);
for (RepositoryFileDto fileInFolder : filesInFolder) {
for (String sourceFileId : sourceFileIds) {
RepositoryFile fileToRestore = getRepository().getFileById(sourceFileId);
if (fileToRestore.getName().equals(fileInFolder.getName())) {
return false;
}
}
}
return true;
}
Aggregations