use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class StreamToTransNodeConverter method convert.
public IRepositoryFileData convert(final InputStream inputStream, final String charset, final String mimeType) {
try {
long size = inputStream.available();
TransMeta transMeta = new TransMeta();
Repository repository = connectToRepository();
Document doc = PDIImportUtil.loadXMLFrom(inputStream);
transMeta.loadXML(doc.getDocumentElement(), repository, false);
TransDelegate delegate = new TransDelegate(repository, this.unifiedRepository);
saveSharedObjects(repository, transMeta);
return new NodeRepositoryFileData(delegate.elementToDataNode(transMeta), size);
} catch (Exception e) {
logger.error(e);
return null;
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData 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;
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);
}
// 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);
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository method renameTransOrJob.
/**
* Renames and optionally moves a file having {@code idObject}. If {@code newDirectory} is <tt>null</tt>, then the
* file is just renamed. If {@code newTitle} is <tt>null</tt>, then the file should keep its name.
* <p/>
* Note, it is expected that the file exists
*
* @param idObject
* file's id
* @param versionComment
* comment on the revision
* @param newDirectory
* new folder, where to move the file; <tt>null</tt> means the file should be left in its current
* @param newTitle
* new file's title (title is a name w/o extension); <tt>null</tt> means the file should keep its current
* @param objectType
* file's type; {@linkplain RepositoryObjectType#TRANSFORMATION} or {@linkplain RepositoryObjectType#JOB} are
* expected
* @param errorMsgKey
* key for the error message passed with the exception
* @throws KettleException
* if file with same path exists
*/
private ObjectId renameTransOrJob(ObjectId idObject, String versionComment, RepositoryDirectoryInterface newDirectory, String newTitle, RepositoryObjectType objectType, String errorMsgKey) throws KettleException {
RepositoryFile file = pur.getFileById(idObject.getId());
RepositoryFile.Builder builder = new RepositoryFile.Builder(file);
// fullName = title + extension
String fullName;
if (newTitle == null) {
// keep existing file name
fullName = file.getName();
} else {
// set new title
builder.title(RepositoryFile.DEFAULT_LOCALE, newTitle).createdDate(null);
fullName = checkAndSanitize(newTitle) + objectType.getExtension();
}
String absPath = calcDestAbsPath(file, newDirectory, fullName);
// get file from destination path, should be null for rename goal
RepositoryFile fileFromDestination = pur.getFile(absPath);
if (fileFromDestination == null) {
file = builder.build();
NodeRepositoryFileData data = pur.getDataAtVersionForRead(file.getId(), null, NodeRepositoryFileData.class);
if (newTitle != null) {
// update file's content only if the title should be changed
// as this action creates another revision
pur.updateFile(file, data, versionComment);
}
pur.moveFile(idObject.getId(), absPath, null);
rootRef.clearRef();
return idObject;
} else {
throw new KettleException(BaseMessages.getString(PKG, errorMsgKey, file.getName(), newTitle));
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository method loadClusterSchema.
@Override
public ClusterSchema loadClusterSchema(ObjectId idClusterSchema, List<SlaveServer> slaveServers, String versionId) throws KettleException {
try {
// We dont need to use slaveServer variable as the dataNoteToElement method finds the server from the repository
NodeRepositoryFileData data = pur.getDataAtVersionForRead(idClusterSchema.getId(), versionId, NodeRepositoryFileData.class);
RepositoryFile file = null;
if (versionId != null) {
file = pur.getFileAtVersion(idClusterSchema.getId(), versionId);
} else {
file = pur.getFileById(idClusterSchema.getId());
}
return clusterTransformer.assemble(file, data, pur.getVersionSummary(idClusterSchema.getId(), versionId));
} catch (Exception e) {
throw new KettleException("Unable to load cluster schema with id [" + idClusterSchema + "]", e);
}
}
use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-kettle by pentaho.
the class PurRepository method loadPartitionSchema.
@Override
public PartitionSchema loadPartitionSchema(ObjectId partitionSchemaId, String versionId) throws KettleException {
try {
NodeRepositoryFileData data = pur.getDataAtVersionForRead(partitionSchemaId.getId(), versionId, NodeRepositoryFileData.class);
RepositoryFile file = null;
if (versionId != null) {
file = pur.getFileAtVersion(partitionSchemaId.getId(), versionId);
} else {
file = pur.getFileById(partitionSchemaId.getId());
}
return partitionSchemaTransformer.assemble(file, data, pur.getVersionSummary(partitionSchemaId.getId(), versionId));
} catch (Exception e) {
throw new KettleException("Unable to load partition schema with id [" + partitionSchemaId + "]", e);
}
}
Aggregations