use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method appendCatalogsSection.
@VisibleForTesting
protected void appendCatalogsSection(IUnifiedRepository unifiedRepository, String etcMondrian, RepositoryFile etcMondrianFolder, StringBuffer datasourcesXML) {
// $NON-NLS-1$
datasourcesXML.append("<Catalogs>\n");
// Creates <Catalogs> from the "/etc/mondrian/<catalog>/metadata" nodes.
/*
* IPentahoSession pentahoSession = PentahoSessionHolder.getSession(); String tenantEtcFolder = null;
* if(pentahoSession != null) { String tenantId = (String)
* pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY); tenantEtcFolder =
* ServerRepositoryPaths.getTenantEtcFolderPath(tenantId); } else { tenantEtcFolder =
* ServerRepositoryPaths.getTenantEtcFolderPath(); }
*/
List<RepositoryFile> mondrianCatalogs = unifiedRepository.getChildren(etcMondrianFolder.getId());
for (RepositoryFile catalog : mondrianCatalogs) {
String catalogName = catalog.getName();
RepositoryFile metadata = unifiedRepository.getFile(etcMondrian + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR + // $NON-NLS-1$
"metadata");
if (metadata != null) {
DataNode metadataNode = unifiedRepository.getDataForRead(metadata.getId(), NodeRepositoryFileData.class).getNode();
// $NON-NLS-1$
String datasourceInfo = metadataNode.getProperty("datasourceInfo").getString();
// $NON-NLS-1$
String definition = metadataNode.getProperty("definition").getString();
datasourcesXML.append(// $NON-NLS-1$ //$NON-NLS-2$
"<Catalog name=\"" + Encode.forXml(catalogName) + "\">\n");
datasourcesXML.append("<DataSourceInfo>" + Encode.forXml(datasourceInfo) + // $NON-NLS-1$
"</DataSourceInfo>\n");
datasourcesXML.append(// $NON-NLS-1$ //$NON-NLS-2$
"<Definition>" + Encode.forXml(definition) + "</Definition>\n");
// $NON-NLS-1$
datasourcesXML.append("</Catalog>\n");
} else {
logger.warn(// $NON-NLS-1$
Messages.getInstance().getString("MondrianCatalogHelper.WARN_META_DATA_IS_NULL"));
}
}
// $NON-NLS-1$
datasourcesXML.append("</Catalogs>\n");
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method removeCatalog.
/**
* This method removes a mondrian catalog from the JCR repository.
*/
@Override
public void removeCatalog(final String catalogName, final IPentahoSession pentahoSession) throws MondrianCatalogServiceException {
if (MondrianCatalogHelper.logger.isDebugEnabled()) {
// $NON-NLS-1$
MondrianCatalogHelper.logger.debug("removeCatalog");
}
MondrianCatalog catalog = getCatalog(catalogName, pentahoSession);
if (catalog == null) {
throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0015_CATALOG_NOT_FOUND", // $NON-NLS-1$
catalogName));
}
if (!hasAccess(catalog, RepositoryFilePermission.WRITE)) {
if (MondrianCatalogHelper.logger.isDebugEnabled()) {
// $NON-NLS-1$
MondrianCatalogHelper.logger.debug("user does not have access; throwing exception");
}
throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0003_INSUFFICIENT_PERMISSION"), // $NON-NLS-1$
Reason.ACCESS_DENIED);
}
flushCacheForCatalog(catalog.getName(), pentahoSession);
getAclHelper().removeAclFor(getMondrianCatalogRepositoryHelper().getMondrianCatalogFile(catalog.getName()));
IUnifiedRepository solutionRepository = getRepository();
RepositoryFile deletingFile = solutionRepository.getFile(// $NON-NLS-1$
RepositoryFile.SEPARATOR + "etc" + RepositoryFile.SEPARATOR + "mondrian" + RepositoryFile.SEPARATOR + // $NON-NLS-1$
catalog.getName());
// $NON-NLS-1$
solutionRepository.deleteFile(deletingFile.getId(), true, "");
reInit(pentahoSession);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class GetResourceIT method testRepositoryFile.
@Test
public void testRepositoryFile() throws ServletException, IOException {
final String repoFileName = "repo_file.jpg";
final int repoFileLength = 100;
final RepositoryFile repositoryFile = mock(RepositoryFile.class);
final InputStream inputStream = mock(InputStream.class);
when(inputStream.read(any(byte[].class))).thenReturn(repoFileLength, -1);
final SimpleRepositoryFileData repositoryFileData = mock(SimpleRepositoryFileData.class);
when(repositoryFileData.getStream()).thenReturn(inputStream);
final IUnifiedRepository repo = mock(IUnifiedRepository.class);
when(repo.getFile(eq(repoFileName))).thenReturn(repositoryFile);
when(repo.getDataForRead(any(Serializable.class), eq(SimpleRepositoryFileData.class))).thenReturn(repositoryFileData);
mp.defineInstance(IUnifiedRepository.class, repo);
when(request.getParameter(RESOURCE_PARAM)).thenReturn(repoFileName);
final ServletOutputStream outputStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outputStream);
servlet.service(request, response);
verify(response).setContentType(eq(TEST_MIME_TYPE));
verify(response).setHeader(eq(CONTENT_DISPOSITION_HEADER), endsWith(repoFileName));
verify(response).setContentLength(repoFileLength);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileStreamProvider method fileCreated.
public void fileCreated(String filePath) {
IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
RepositoryFile outputFile = repository.getFile(filePath);
if (outputFile != null) {
Map<String, Serializable> fileMetadata = repository.getFileMetadata(outputFile.getId());
RepositoryFile inputFile = repository.getFile(inputFilePath);
if (inputFile != null) {
fileMetadata.put(PentahoJcrConstants.PHO_CONTENTCREATOR, inputFile.getId());
repository.setFileMetadata(outputFile.getId(), fileMetadata);
}
}
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class ActionSequenceContentGenerator method createContent.
public void createContent(OutputStream outputStream) throws Exception {
IParameterProvider requestParams = getRequestParameters();
IParameterProvider pathParams = getPathParameters();
if (// $NON-NLS-1$
(requestParams != null) && (requestParams.getStringParameter("path", null) != null)) {
// So far the decode that used to be here is not necessary and breaks files with special characters.
// Leaving commented code here in case it shows up later
// path = URLDecoder.decode( requestParams.getStringParameter( "path", "" ), "UTF-8" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
path = requestParams.getStringParameter("path", "");
} else if ((pathParams != null) && (pathParams.getStringParameter("path", null) != null)) {
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
path = URLDecoder.decode(pathParams.getStringParameter("path", ""), "UTF-8");
}
if ((requestParams != null) && (requestParams.getStringParameter("contentType", null) != null)) {
// $NON-NLS-1$
// $NON-NLS-1$
contentType = requestParams.getStringParameter("contentType", TEXT_HTML);
} else if ((pathParams != null) && (pathParams.getStringParameter("contentType", null) != null)) {
// $NON-NLS-1$
// $NON-NLS-1$
contentType = pathParams.getStringParameter("contentType", TEXT_HTML);
}
if (path != null && path.length() > 0) {
IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
RepositoryFile file = unifiedRepository.getFile(path);
// $NON-NLS-1$
HttpServletRequest httpRequest = (HttpServletRequest) pathParams.getParameter("httprequest");
// $NON-NLS-1$
HttpServletResponse httpResponse = (HttpServletResponse) pathParams.getParameter("httpresponse");
String buffer = XactionUtil.execute(contentType, file, httpRequest, httpResponse, PentahoSessionHolder.getSession(), outputHandler.getMimeTypeListener());
if (buffer != null && buffer.trim().length() > 0) {
outputStream.write(buffer.getBytes(LocaleHelper.getSystemEncoding()));
}
}
}
Aggregations