use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class FileService method doRename.
/**
* Rename the name of the selected file
*
* @param pathId (colon separated path for the repository file)
* @param newName (New name of the file)
* @return
*/
public boolean doRename(String pathId, String newName) throws Exception {
IUnifiedRepository repository = getRepository();
RepositoryFile fileToBeRenamed = repository.getFile(FileUtils.idToPath(pathId));
StringBuilder buf = new StringBuilder(fileToBeRenamed.getPath().length());
buf.append(getParentPath(fileToBeRenamed.getPath()));
buf.append(RepositoryFile.SEPARATOR);
buf.append(newName);
if (!fileToBeRenamed.isFolder()) {
String extension = getExtension(fileToBeRenamed.getName());
if (extension != null) {
buf.append(extension);
}
}
repository.moveFile(fileToBeRenamed.getId(), buf.toString(), "Renaming the file");
RepositoryFile movedFile = repository.getFileById(fileToBeRenamed.getId());
if (movedFile != null) {
if (!movedFile.isFolder()) {
Map<String, Properties> localePropertiesMap = movedFile.getLocalePropertiesMap();
if (localePropertiesMap == null) {
localePropertiesMap = new HashMap<String, Properties>();
Properties properties = new Properties();
properties.setProperty("file.title", newName);
properties.setProperty("title", newName);
localePropertiesMap.put("default", properties);
} else {
for (Map.Entry<String, Properties> entry : localePropertiesMap.entrySet()) {
Properties properties = entry.getValue();
if (properties.containsKey("file.title")) {
properties.setProperty("file.title", newName);
}
if (properties.containsKey("title")) {
properties.setProperty("title", newName);
}
}
}
RepositoryFile updatedFile = new RepositoryFile.Builder(movedFile).localePropertiesMap(localePropertiesMap).name(newName).title(newName).build();
repository.updateFile(updatedFile, RepositoryFileHelper.getFileData(movedFile), "Updating the file");
}
return true;
} else {
return false;
// return Response.ok( "File to be renamed does not exist" ).build();
}
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class XactionUtil method postExecute.
public static String postExecute(IRuntimeContext runtime, boolean debugMessages, boolean doWrapper, IOutputHandler outputHandler, Map<String, IParameterProvider> parameterProviders, HttpServletRequest request, HttpServletResponse response, List<?> messages, boolean deleteGeneratedFiles) throws Exception {
StringBuffer buffer = new StringBuffer();
boolean hasResponse = outputHandler.isResponseExpected();
IContentItem responseContentItem = outputHandler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
boolean success = (runtime != null && runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS);
boolean printSuccess = (runtime != null) && success && (!hasResponse || debugMessages);
boolean printError = (runtime != null) && !success && !response.isCommitted();
if (printSuccess || printError) {
// $NON-NLS-1$
final String htmlMimeType = "text/html";
responseContentItem.setMimeType(htmlMimeType);
response.setContentType(htmlMimeType);
if (printSuccess) {
MessageFormatUtils.formatSuccessMessage(htmlMimeType, runtime, buffer, debugMessages, doWrapper);
} else {
response.resetBuffer();
MessageFormatUtils.formatFailureMessage(htmlMimeType, runtime, buffer, messages);
}
}
// clear files which was generated during action execution
// http://jira.pentaho.com/browse/BISERVER-12639
IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
if (unifiedRepository != null) {
for (IContentItem contentItem : runtime.getOutputContentItems()) {
if (contentItem != null) {
try {
contentItem.closeOutputStream();
if (deleteGeneratedFiles) {
deleteContentItem(contentItem, unifiedRepository);
}
} catch (Exception e) {
logger.warn(Messages.getInstance().getString("XactionUtil.CANNOT_REMOVE_OUTPUT_FILE", contentItem.getPath()), e);
}
}
}
}
return buffer.toString();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class ActionUtil method sendEmail.
/**
* Sends an email with the file representing the provided {@code filePath} as an attachment. All information
* needed to send the email (to, from, cc, bcc etc) is expected to be proviced in the {@code actionParams}
* {@link Map}.
*
* @param actionParams a {@link Map} of parameters needed to send the email
* @param params a {@link Map} of parameter used to invoke the action
* @param filePath the path of the repository file that was generated when the action was invoked
*/
public static void sendEmail(Map<String, Object> actionParams, Map<String, Serializable> params, String filePath) {
try {
IUnifiedRepository repo = PentahoSystem.get(IUnifiedRepository.class);
RepositoryFile sourceFile = repo.getFile(filePath);
// add metadata
Map<String, Serializable> metadata = repo.getFileMetadata(sourceFile.getId());
String lineageId = (String) params.get(ActionUtil.QUARTZ_LINEAGE_ID);
metadata.put(ActionUtil.QUARTZ_LINEAGE_ID, lineageId);
repo.setFileMetadata(sourceFile.getId(), metadata);
// send email
SimpleRepositoryFileData data = repo.getDataForRead(sourceFile.getId(), SimpleRepositoryFileData.class);
// if email is setup and we have tos, then do it
Emailer emailer = new Emailer();
if (!emailer.setup()) {
// email not configured
return;
}
String to = (String) actionParams.get("_SCH_EMAIL_TO");
String cc = (String) actionParams.get("_SCH_EMAIL_CC");
String bcc = (String) actionParams.get("_SCH_EMAIL_BCC");
if ((to == null || "".equals(to)) && (cc == null || "".equals(cc)) && (bcc == null || "".equals(bcc))) {
// no destination
return;
}
emailer.setTo(to);
emailer.setCc(cc);
emailer.setBcc(bcc);
emailer.setAttachment(data.getInputStream());
emailer.setAttachmentName("attachment");
String attachmentName = (String) actionParams.get("_SCH_EMAIL_ATTACHMENT_NAME");
if (attachmentName != null && !"".equals(attachmentName)) {
String path = filePath;
if (path.endsWith(".*")) {
path = path.replace(".*", "");
}
String extension = MimeHelper.getExtension(data.getMimeType());
if (extension == null) {
extension = ".bin";
}
if (!attachmentName.endsWith(extension)) {
emailer.setAttachmentName(attachmentName + extension);
} else {
emailer.setAttachmentName(attachmentName);
}
} else if (data != null) {
String path = filePath;
if (path.endsWith(".*")) {
path = path.replace(".*", "");
}
String extension = MimeHelper.getExtension(data.getMimeType());
if (extension == null) {
extension = ".bin";
}
path = path.substring(path.lastIndexOf("/") + 1, path.length());
if (!path.endsWith(extension)) {
emailer.setAttachmentName(path + extension);
} else {
emailer.setAttachmentName(path);
}
}
if (data == null || data.getMimeType() == null || "".equals(data.getMimeType())) {
emailer.setAttachmentMimeType("binary/octet-stream");
} else {
emailer.setAttachmentMimeType(data.getMimeType());
}
String subject = (String) actionParams.get("_SCH_EMAIL_SUBJECT");
if (subject != null && !"".equals(subject)) {
emailer.setSubject(subject);
} else {
emailer.setSubject("Pentaho Scheduler: " + emailer.getAttachmentName());
}
String message = (String) actionParams.get("_SCH_EMAIL_MESSAGE");
if (subject != null && !"".equals(subject)) {
emailer.setBody(message);
}
emailer.send();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileStreamProvider method getInputStream.
public InputStream getInputStream() throws Exception {
IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
RepositoryFile repositoryFile = repository.getFile(inputFilePath);
if ((repositoryFile == null) || repositoryFile.isFolder()) {
throw new FileNotFoundException();
}
return new RepositoryFileInputStream(repositoryFile);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class ActionSequenceParameterContentGenerator method createContent.
@Override
public void createContent(OutputStream outputStream) throws Exception {
IParameterProvider requestParams = getRequestParameters();
IParameterProvider pathParams = getPathParameters();
if ((requestParams != null) && (requestParams.getStringParameter("path", null) != null)) {
path = URLDecoder.decode(requestParams.getStringParameter("path", ""), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"UTF-8");
} else if ((pathParams != null) && (pathParams.getStringParameter("path", null) != null)) {
// $NON-NLS-1$
path = URLDecoder.decode(pathParams.getStringParameter("path", ""), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"UTF-8");
}
if (path != null && path.length() > 0) {
IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
RepositoryFile file = unifiedRepository.getFile(path);
String buffer = XactionUtil.doParameter(file, requestParams, PentahoSessionHolder.getSession());
outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
}
}
Aggregations