use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.
the class KettleFileRepository method save.
public void save(RepositoryElementInterface repositoryElement, String versionComment, ProgressMonitorListener monitor, ObjectId parentId, boolean used) throws KettleException {
try {
if (!(repositoryElement instanceof XMLInterface) && !(repositoryElement instanceof SharedObjectInterface)) {
throw new KettleException("Class [" + repositoryElement.getClass().getName() + "] needs to implement the XML Interface in order to save it to disk");
}
if (!Utils.isEmpty(versionComment)) {
insertLogEntry("Save repository element : " + repositoryElement.toString() + " : " + versionComment);
}
ObjectId objectId = new StringObjectId(calcObjectId(repositoryElement));
FileObject fileObject = getFileObject(repositoryElement);
String xml = ((XMLInterface) repositoryElement).getXML();
OutputStream os = KettleVFS.getOutputStream(fileObject, false);
os.write(xml.getBytes(Const.XML_ENCODING));
os.close();
if (repositoryElement instanceof ChangedFlagInterface) {
((ChangedFlagInterface) repositoryElement).clearChanged();
}
//
if (repositoryElement.getObjectId() != null && !repositoryElement.getObjectId().equals(objectId)) {
delObject(repositoryElement.getObjectId());
}
repositoryElement.setObjectId(objectId);
//
if (repositoryElement instanceof TransMeta) {
((TransMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
}
if (repositoryElement instanceof JobMeta) {
((JobMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
}
} catch (Exception e) {
throw new KettleException("Unable to save repository element [" + repositoryElement + "] to XML file : " + calcFilename(repositoryElement), e);
}
}
use of org.pentaho.di.core.changed.ChangedFlagInterface 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.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.
the class PurRepository method saveDatabaseMeta.
protected void saveDatabaseMeta(final RepositoryElementInterface element, final String versionComment, Calendar versionDate) throws KettleException {
readWriteLock.writeLock().lock();
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);
}
} finally {
readWriteLock.writeLock().unlock();
}
}
use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.
the class Spoon method setShellText.
public void setShellText() {
if (shell.isDisposed()) {
return;
}
String filename = null;
String name = null;
String version = null;
ChangedFlagInterface changed = null;
boolean versioningEnabled = true;
AbstractMeta meta = getActiveJob() != null ? getActiveJob() : getActiveTransformation();
if (meta != null) {
changed = meta;
filename = meta.getFilename();
name = meta.getName();
version = meta.getObjectRevision() == null ? null : meta.getObjectRevision().getName();
try {
versioningEnabled = isVersionEnabled(rep, meta);
} catch (KettleRepositoryLostException krle) {
handleRepositoryLost(krle);
}
}
String text = "";
if (rep != null) {
text += APP_TITLE + " - [" + getRepositoryName() + "] ";
} else {
text += APP_TITLE + " - ";
}
if (Utils.isEmpty(name)) {
if (!Utils.isEmpty(filename)) {
text += filename;
} else {
String tab = getActiveTabText();
if (!Utils.isEmpty(tab)) {
text += tab;
} else {
// "[no name]"
text += BaseMessages.getString(PKG, "Spoon.Various.NoName");
}
}
} else {
text += name;
}
if (versioningEnabled && !Utils.isEmpty(version)) {
text += " v" + version;
}
if (changed != null && changed.hasChanged()) {
text += " " + BaseMessages.getString(PKG, "Spoon.Various.Changed");
}
shell.setText(text);
markTabsChanged(false);
}
use of org.pentaho.di.core.changed.ChangedFlagInterface in project pentaho-kettle by pentaho.
the class PurRepository method saveRepositoryElement.
protected void saveRepositoryElement(RepositoryElementInterface element, String versionComment, ITransformer transformer, Serializable elementsFolderId) throws KettleException {
boolean isUpdate = (element.getObjectId() != null);
RepositoryFile file;
readWriteLock.writeLock().lock();
try {
if (isUpdate) {
file = pur.getFileById(element.getObjectId().getId());
// update title & description
file = new RepositoryFile.Builder(file).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).build();
// first rename, it is safe as only a name is changed, but not a path
renameIfNecessary(element, file);
file = pur.updateFile(file, new NodeRepositoryFileData(transformer.elementToDataNode(element)), versionComment);
} else {
file = new RepositoryFile.Builder(checkAndSanitize(element.getName() + element.getRepositoryElementType().getExtension())).title(RepositoryFile.DEFAULT_LOCALE, element.getName()).description(RepositoryFile.DEFAULT_LOCALE, Const.NVL(element.getDescription(), "")).versioned(VERSION_SHARED_OBJECTS).build();
file = pur.createFile(elementsFolderId, file, new NodeRepositoryFileData(transformer.elementToDataNode(element)), versionComment);
}
} finally {
readWriteLock.writeLock().unlock();
}
// 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);
}
Aggregations