use of org.pentaho.di.repository.StringObjectId in project pentaho-kettle by pentaho.
the class PurRepository method getDatabaseID.
@Override
public ObjectId getDatabaseID(final String name) throws KettleException {
try {
ObjectId objectId = getObjectId(name, null, RepositoryObjectType.DATABASE, false);
if (objectId == null) {
List<RepositoryFile> allDatabases = getAllFilesOfType(null, RepositoryObjectType.DATABASE, false);
String[] existingNames = new String[allDatabases.size()];
for (int i = 0; i < allDatabases.size(); i++) {
RepositoryFile file = allDatabases.get(i);
existingNames[i] = file.getTitle();
}
int index = DatabaseMeta.indexOfName(existingNames, name);
if (index != -1) {
return new StringObjectId(allDatabases.get(index).getId().toString());
}
}
return objectId;
} catch (Exception e) {
throw new KettleException("Unable to get ID for database [" + name + "]", e);
}
}
use of org.pentaho.di.repository.StringObjectId 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.di.repository.StringObjectId in project pentaho-kettle by pentaho.
the class PurRepository method saveRepositoryDirectory.
@Override
public void saveRepositoryDirectory(final RepositoryDirectoryInterface dir) throws KettleException {
try {
// id of root dir is null--check for it
if ("/".equals(dir.getParent().getName())) {
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.FailedDirectoryCreation.Message"));
}
RepositoryFile newFolder = pur.createFolder(dir.getParent().getObjectId() != null ? dir.getParent().getObjectId().getId() : null, new RepositoryFile.Builder(dir.getName()).folder(true).build(), null);
dir.setObjectId(new StringObjectId(newFolder.getId().toString()));
} catch (Exception e) {
throw new KettleException("Unable to save repository directory with path [" + getPath(null, dir, null) + "]", e);
}
}
use of org.pentaho.di.repository.StringObjectId 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.di.repository.StringObjectId 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);
}
}
Aggregations