use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository method loadTransformations.
/**
* Load all transformations referenced by {@code files}.
*
* @param monitor
* @param log
* @param files
* Transformation files to load.
* @param setInternalVariables
* Should internal variables be set when loading? (Note: THIS IS IGNORED, they are always set)
* @return Loaded transformations
* @throws KettleException
* Error loading data for transformations from repository
*/
protected List<TransMeta> loadTransformations(final ProgressMonitorListener monitor, final LogChannelInterface log, final List<RepositoryFile> files, final boolean setInternalVariables) throws KettleException {
List<TransMeta> transformations = new ArrayList<TransMeta>(files.size());
List<NodeRepositoryFileData> filesData = pur.getDataForReadInBatch(files, NodeRepositoryFileData.class);
List<VersionSummary> versions = pur.getVersionSummaryInBatch(files);
Iterator<RepositoryFile> filesIter = files.iterator();
Iterator<NodeRepositoryFileData> filesDataIter = filesData.iterator();
Iterator<VersionSummary> versionsIter = versions.iterator();
while ((monitor == null || !monitor.isCanceled()) && filesIter.hasNext()) {
RepositoryFile file = filesIter.next();
NodeRepositoryFileData fileData = filesDataIter.next();
VersionSummary version = versionsIter.next();
String dirPath = file.getPath().substring(0, file.getPath().lastIndexOf(RepositoryDirectory.DIRECTORY_SEPARATOR));
try {
log.logDetailed("Loading/Exporting transformation [{0} : {1}] ({2})", dirPath, file.getTitle(), file.getPath());
if (monitor != null) {
// $NON-NLS-1$ //$NON-NLS-2$
monitor.subTask("Exporting transformation [" + file.getPath() + "]");
}
TransMeta transMeta = buildTransMeta(file, findDirectory(dirPath), fileData, createObjectRevision(version));
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationMetaLoaded.id, transMeta);
transformations.add(transMeta);
} catch (Exception ex) {
// $NON-NLS-1$ //$NON-NLS-2$
log.logDetailed("Unable to load transformation [" + file.getPath() + "]", ex);
log.logError("An error occurred reading transformation [" + file.getTitle() + "] from directory [" + dirPath + "] : " + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ex.getMessage());
log.logError("Transformation [" + file.getTitle() + "] from directory [" + dirPath + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"] was not exported because of a loading error!");
}
}
return transformations;
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository method loadJob.
@Override
public JobMeta loadJob(String jobname, RepositoryDirectoryInterface parentDir, ProgressMonitorListener monitor, String versionId) throws KettleException {
String absPath = null;
try {
absPath = getPath(jobname, parentDir, RepositoryObjectType.JOB);
if (absPath == null) {
// Couldn't resolve path, throw an exception
throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0003_JOB_NOT_FOUND", jobname));
}
RepositoryFile file = pur.getFile(absPath);
if (versionId != null) {
// need to go back to server to get versioned info
file = pur.getFileAtVersion(file.getId(), versionId);
}
NodeRepositoryFileData data = null;
ObjectRevision revision = null;
data = pur.getDataAtVersionForRead(file.getId(), versionId, NodeRepositoryFileData.class);
revision = getObjectRevision(new StringObjectId(file.getId().toString()), versionId);
JobMeta jobMeta = buildJobMeta(file, parentDir, data, revision);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobMetaLoaded.id, jobMeta);
return jobMeta;
} catch (Exception e) {
throw new KettleException("Unable to load job from path [" + absPath + "]", e);
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository method saveDatabaseMeta.
protected void saveDatabaseMeta(final RepositoryElementInterface element, final String versionComment, Calendar versionDate) throws KettleException {
try {
//
if (element.getObjectId() == null) {
element.setObjectId(getDatabaseID(element.getName()));
}
boolean isUpdate = element.getObjectId() != null;
RepositoryFile file = null;
if (isUpdate) {
file = pur.getFileById(element.getObjectId().getId());
// update title
final String title = ((DatabaseMeta) element).getDisplayName();
Date modifiedDate = null;
if (versionDate != null && versionDate.getTime() != null) {
modifiedDate = versionDate.getTime();
} else {
modifiedDate = new Date();
}
file = new RepositoryFile.Builder(file).title(RepositoryFile.DEFAULT_LOCALE, title).lastModificationDate(modifiedDate).build();
renameIfNecessary(element, file);
file = pur.updateFile(file, new NodeRepositoryFileData(databaseMetaTransformer.elementToDataNode(element)), versionComment);
} else {
Date createdDate = null;
if (versionDate != null && versionDate.getTime() != null) {
createdDate = versionDate.getTime();
} else {
createdDate = new Date();
}
file = new RepositoryFile.Builder(checkAndSanitize(RepositoryFilenameUtils.escape(element.getName(), pur.getReservedChars()) + RepositoryObjectType.DATABASE.getExtension())).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).createdDate(createdDate).versioned(VERSION_SHARED_OBJECTS).build();
file = pur.createFile(getDatabaseMetaParentFolderId(), file, new NodeRepositoryFileData(databaseMetaTransformer.elementToDataNode(element)), versionComment);
}
// side effects
ObjectId objectId = new StringObjectId(file.getId().toString());
element.setObjectId(objectId);
element.setObjectRevision(getObjectRevision(objectId, null));
if (element instanceof ChangedFlagInterface) {
((ChangedFlagInterface) element).clearChanged();
}
updateSharedObjectCache(element);
} catch (Exception e) {
// determine if there is an "access denied" issue and throw a nicer error message.
if (e.getMessage().indexOf("access denied") >= 0) {
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.ERROR_0004_DATABASE_UPDATE_ACCESS_DENIED", element.getName()), e);
}
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository method saveTransOrJob.
protected void saveTransOrJob(ISharedObjectsTransformer objectTransformer, RepositoryElementInterface element, String versionComment, Calendar versionDate, boolean saveSharedObjects, boolean checkLock, boolean checkRename, boolean loadRevision, boolean checkDeleted) throws KettleException {
if (Import.ROOT_DIRECTORY.equals(element.getRepositoryDirectory().toString())) {
// We don't have possibility to read this file via UI
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.fileCannotBeSavedInRootDirectory", element.getName() + element.getRepositoryElementType().getExtension()));
}
if (saveSharedObjects) {
objectTransformer.saveSharedObjects(element, versionComment);
}
final boolean isUpdate = (element.getObjectId() != null);
RepositoryFile file;
if (isUpdate) {
ObjectId id = element.getObjectId();
file = pur.getFileById(id.getId());
if (checkLock && file.isLocked() && !unifiedRepositoryLockService.canUnlockFileById(id)) {
throw new KettleException("File is currently locked by another user for editing");
}
if (checkDeleted && isInTrash(file)) {
// absolutely awful to have UI references in this class :(
throw new KettleException("File is in the Trash. Use Save As.");
}
// update title and description
file = new RepositoryFile.Builder(file).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).createdDate(versionDate != null ? versionDate.getTime() : new Date()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).build();
try {
file = pur.updateFile(file, new NodeRepositoryFileData(objectTransformer.elementToDataNode(element)), versionComment);
} catch (SOAPFaultException e) {
if (e.getMessage().contains(UnifiedRepositoryUpdateFileException.PREFIX)) {
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.fileUpdateException", file.getName()));
}
throw e;
}
if (checkRename && isRenamed(element, file)) {
renameKettleEntity(element, null, element.getName());
}
} else {
file = new RepositoryFile.Builder(checkAndSanitize(element.getName() + element.getRepositoryElementType().getExtension())).versioned(true).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).createdDate(versionDate != null ? versionDate.getTime() : new Date()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).build();
try {
file = pur.createFile(element.getRepositoryDirectory().getObjectId().getId(), file, new NodeRepositoryFileData(objectTransformer.elementToDataNode(element)), versionComment);
} catch (SOAPFaultException e) {
if (e.getMessage().contains(UnifiedRepositoryCreateFileException.PREFIX)) {
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.fileCreateException", file.getName()));
}
}
}
// side effects
ObjectId objectId = new StringObjectId(file.getId().toString());
element.setObjectId(objectId);
if (loadRevision) {
element.setObjectRevision(getObjectRevision(objectId, null));
}
if (element instanceof ChangedFlagInterface) {
((ChangedFlagInterface) element).clearChanged();
}
if (element.getRepositoryElementType() == RepositoryObjectType.TRANSFORMATION) {
TransMeta transMeta = loadTransformation(objectId, null);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransImportAfterSaveToRepo.id, transMeta);
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testGetDatasources.
@Test
public void testGetDatasources() throws Exception {
final String fileId = "456";
final String databasesFolderPath = "/etc/pdi/databases";
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to update
RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
final String EXP_HOST_NAME = "hello";
DataNode rootNode = new DataNode("databaseMeta");
// required
rootNode.setProperty("TYPE", "Hypersonic");
rootNode.setProperty("HOST_NAME", EXP_HOST_NAME);
// required
rootNode.addNode("attributes");
doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(eq(fileId), eq(NodeRepositoryFileData.class));
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName(EXP_DBMETA_NAME);
assertEquals(EXP_HOST_NAME, conn.getHostname());
}
Aggregations