use of org.pentaho.di.repository.ObjectId 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);
}
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.BeforeSaveToRepository.id, element);
final boolean isUpdate = (element.getObjectId() != null);
RepositoryFile file = null;
if (isUpdate) {
readWriteLock.readLock().lock();
try {
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.");
}
} finally {
readWriteLock.readLock().unlock();
}
readWriteLock.writeLock().lock();
try {
// 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();
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;
} finally {
readWriteLock.writeLock().unlock();
}
if (checkRename && isRenamed(element, file)) {
renameKettleEntity(element, null, element.getName());
}
} else {
readWriteLock.writeLock().lock();
try {
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();
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()));
}
} finally {
readWriteLock.writeLock().unlock();
}
}
// 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.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class LazyUnifiedRepositoryDirectory method getDirectoryIDs.
@Override
public ObjectId[] getDirectoryIDs() {
List<RepositoryFile> children = this.getAllURChildrenFiles();
ObjectId[] objectIds = new ObjectId[children.size()];
for (int i = 0; i < children.size(); i++) {
objectIds[i] = new StringObjectId(children.get(i).getId().toString());
}
return objectIds;
}
use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class PurRepositoryAttribute method getAttributeDatabaseMeta.
public DatabaseMeta getAttributeDatabaseMeta(String code) {
DataProperty property = dataNode.getProperty(code);
if (property == null || Utils.isEmpty(property.getString())) {
return null;
}
ObjectId id = new StringObjectId(property.getString());
return DatabaseMeta.findDatabase(databases, id);
}
use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class RepositoryDirectoryUI method chooseDirectory.
public static RepositoryDirectoryInterface chooseDirectory(Shell shell, Repository rep, RepositoryDirectoryInterface directoryFrom) {
if (rep == null) {
return null;
}
if (directoryFrom == null) {
try {
directoryFrom = rep.getUserHomeDirectory();
} catch (KettleException ex) {
directoryFrom = new RepositoryDirectory();
}
}
ObjectId idDirectoryFrom = directoryFrom.getObjectId();
SelectDirectoryDialog sdd = new SelectDirectoryDialog(shell, SWT.NONE, rep);
// PDI-13867: root dir and its direct subdirectories are restricted.
HashSet<String> restrictedPaths = new HashSet<String>();
restrictedPaths.add(directoryFrom.findRoot().getPath());
restrictedPaths.add("/home");
sdd.setRestrictedPaths(restrictedPaths);
// TODO: expand and select directoryFrom in the dialog.
RepositoryDirectoryInterface rd = sdd.open();
if (rd == null || idDirectoryFrom == rd.getObjectId()) {
return null;
}
return rd;
}
use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method newCluster.
public void newCluster() {
try {
ClusterSchema cluster = new ClusterSchema();
ClusterSchemaDialog dd = new ClusterSchemaDialog(shell, cluster, rep.getSlaveServers());
if (dd.open()) {
// See if this slave server already exists...
ObjectId idCluster = rep.getClusterID(cluster.getName());
if (idCluster == null) {
rep.insertLogEntry("Creating new cluster '" + cluster.getName() + "'");
rep.save(cluster, Const.VERSION_COMMENT_INITIAL_VERSION, null);
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.AlreadyExists.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.AlreadyExists.Title"));
mb.open();
}
// Refresh tree...
refreshTree();
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Create.UnexpectedError.Message"), e);
}
}
Aggregations