use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.
the class MetadataDatasourceService method storeDomain.
/**
* @param metadataFile
* Input stream for the metadata.xmi
* @param domainId
* Unique identifier for the metadata datasource
*
* @return Response containing the success of the method
*
* @throws PentahoAccessControlException
* Thrown when validation of access fails
*/
@PUT
@Path("/storeDomain")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, TEXT_PLAIN })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response storeDomain(InputStream metadataFile, @QueryParam("domainId") String domainId) throws PentahoAccessControlException {
try {
DatasourceService.validateAccess();
PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
metadataImporter.storeDomain(metadataFile, domainId, true);
return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
} catch (PentahoAccessControlException e) {
return Response.serverError().entity(e.toString()).build();
} catch (Exception e) {
return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
}
}
use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.
the class MetadataDatasourceService method uploadServletImportMetadataDatasource.
/**
* @param localizeBundleEntries
* @param domainId
* Unique identifier for the metadata datasource
* @param metadataFile
* Input stream for the metadata.xmi
*
* @return Response containing the success of the method
*
* @throws PentahoAccessControlException
* Thrown when validation of access fails
*/
@PUT
@Path("/uploadServletImport")
@Consumes({ TEXT_PLAIN })
@Produces("text/plain")
@Deprecated
@Facet(name = "Unsupported")
public Response uploadServletImportMetadataDatasource(String localizeBundleEntries, @QueryParam("domainId") String domainId, @QueryParam("metadataFile") String metadataFile) throws PentahoAccessControlException {
try {
DatasourceService.validateAccess();
} catch (PentahoAccessControlException e) {
return Response.serverError().entity(e.toString()).build();
}
IMetadataDomainRepository metadataDomainRepository = PentahoSystem.get(IMetadataDomainRepository.class, PentahoSessionHolder.getSession());
PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
CsvUtils csvUtils = new CsvUtils();
boolean validPropertyFiles = true;
StringBuffer invalidFiles = new StringBuffer();
try {
String TMP_FILE_PATH = File.separatorChar + "system" + File.separatorChar + "tmp" + File.separatorChar;
String sysTmpDir = PentahoSystem.getApplicationContext().getSolutionPath(TMP_FILE_PATH);
FileInputStream metadataInputStream = new FileInputStream(sysTmpDir + File.separatorChar + metadataFile);
metadataImporter.storeDomain(metadataInputStream, domainId, true);
metadataDomainRepository.getDomain(domainId);
StringTokenizer bundleEntriesParam = new StringTokenizer(localizeBundleEntries, ";");
while (bundleEntriesParam.hasMoreTokens()) {
String localizationBundleElement = bundleEntriesParam.nextToken();
StringTokenizer localizationBundle = new StringTokenizer(localizationBundleElement, "=");
String localizationFileName = localizationBundle.nextToken();
String localizationFile = localizationBundle.nextToken();
if (localizationFileName.endsWith(".properties")) {
String encoding = csvUtils.getEncoding(localizationFile);
if (ENCODINGS.contains(encoding)) {
for (final Pattern propertyBundlePattern : patterns) {
final Matcher propertyBundleMatcher = propertyBundlePattern.matcher(localizationFileName);
if (propertyBundleMatcher.matches()) {
FileInputStream bundleFileInputStream = new FileInputStream(sysTmpDir + File.separatorChar + localizationFile);
metadataImporter.addLocalizationFile(domainId, propertyBundleMatcher.group(2), bundleFileInputStream, true);
break;
}
}
} else {
validPropertyFiles = false;
invalidFiles.append(localizationFileName);
}
} else {
validPropertyFiles = false;
invalidFiles.append(localizationFileName);
}
}
if (!validPropertyFiles) {
return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_002_PROPERTY_FILES_ERROR") + invalidFiles.toString()).build();
}
return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
} catch (Exception e) {
metadataImporter.removeDomain(domainId);
return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
}
}
use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.
the class MetadataDatasourceService method addLocalizationFile.
/**
* @param domainId
* Unique identifier for the metadata datasource
* @param locale
* String value of the locale
* @param propertiesFile
* Input stream of the properties file
*
* @return Response containing the success of the method
*
* @throws PentahoAccessControlException
* Thrown when validation of access fails
*/
@PUT
@Path("/addLocalizationFile")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, TEXT_PLAIN })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response addLocalizationFile(@QueryParam("domainId") String domainId, @QueryParam("locale") String locale, InputStream propertiesFile) throws PentahoAccessControlException {
try {
DatasourceService.validateAccess();
PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
metadataImporter.addLocalizationFile(domainId, locale, propertiesFile, true);
return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
} catch (PentahoAccessControlException e) {
return Response.serverError().entity(e.toString()).build();
} catch (Exception e) {
return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
}
}
use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.
the class DatasourceResourceIT method createMetadataDomainRepository.
private static PentahoMetadataDomainRepository createMetadataDomainRepository() throws Exception {
IUnifiedRepository repository = new FileSystemBackedUnifiedRepository("target/test-classes/dsw");
mp.defineInstance(IUnifiedRepository.class, repository);
Assert.assertNotNull(new RepositoryUtils(repository).getFolder("/etc/metadata", true, true, null));
Assert.assertNotNull(new RepositoryUtils(repository).getFolder("/etc/mondrian", true, true, null));
PentahoMetadataDomainRepository pentahoMetadataDomainRepository = new PentahoMetadataDomainRepository(repository);
return pentahoMetadataDomainRepository;
}
use of org.pentaho.platform.plugin.services.metadata.PentahoMetadataDomainRepository in project data-access by pentaho.
the class MetadataServiceTest method testGetMetadataDatasourceAcl.
@Test
public void testGetMetadataDatasourceAcl() throws Exception {
String domainId = DOMAIN_ID;
final RepositoryFileAcl acl = new RepositoryFileAcl.Builder("owner").build();
doReturn(true).when(metadataService).canManageACL();
when(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(acl);
final Map<String, InputStream> domainFilesData = mock(Map.class);
when(domainFilesData.isEmpty()).thenReturn(false);
when(((PentahoMetadataDomainRepository) metadataService.metadataDomainRepository).getDomainFilesData(domainId)).thenReturn(domainFilesData);
final RepositoryFileAclDto aclDto = metadataService.getMetadataAcl(domainId);
verify(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
assertEquals(acl, new RepositoryFileAclAdapter().unmarshal(aclDto));
}
Aggregations