use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method getElementType.
@Override
public IMetaStoreElementType getElementType(String namespace, String elementTypeId) throws MetaStoreException {
RepositoryFile elementTypeFolder = pur.getFileById(elementTypeId);
if (elementTypeFolder == null) {
return null;
}
IMetaStoreElementType elementType = newElementType(namespace);
elementType.setId(elementTypeFolder.getId().toString());
elementType.setName(elementTypeFolder.getName());
RepositoryFile detailsFile = findChildByName(elementTypeFolder.getId(), ELEMENT_TYPE_DETAILS_FILENAME, true);
if (detailsFile != null) {
NodeRepositoryFileData data = pur.getDataForRead(detailsFile.getId(), NodeRepositoryFileData.class);
DataProperty property = data.getNode().getProperty("element_type_description");
if (property != null) {
elementType.setDescription(property.getString());
}
}
return elementType;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method getNamespaces.
@Override
public List<String> getNamespaces() throws MetaStoreException {
List<String> namespaces = new ArrayList<String>();
List<RepositoryFile> children = getChildren(namespacesFolder.getId());
for (RepositoryFile child : children) {
namespaces.add(child.getName());
}
return namespaces;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method deleteElementType.
@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
RepositoryFile namespaceRepositoryFile = validateNamespace(namespace);
RepositoryFile elementTypeFile = findChildByName(namespaceRepositoryFile.getId(), elementType.getName());
List<RepositoryFile> children = getChildren(elementTypeFile.getId());
removeHiddenFilesFromList(children);
if (children.isEmpty()) {
pur.deleteFile(elementTypeFile.getId(), true, null);
} else {
List<String> ids = getElementIds(namespace, elementType);
throw new MetaStoreDependenciesExistsException(ids, "Can't delete element type with name '" + elementType.getName() + "' because it is not empty");
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository method loadTransformation.
@Override
public TransMeta loadTransformation(final String transName, final RepositoryDirectoryInterface parentDir, final ProgressMonitorListener monitor, final boolean setInternalVariables, final String versionId) throws KettleException {
String absPath = null;
try {
// by the user
if (StringUtils.isBlank(transName)) {
throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0007_TRANSFORMATION_NAME_MISSING"));
}
try {
absPath = getPath(transName, parentDir, RepositoryObjectType.TRANSFORMATION);
} catch (Exception e) {
// ignore and handle null value below
}
// variable that is not available at runtime
if (StringUtils.isBlank(absPath)) {
// Couldn't resolve path, throw an exception
throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", transName));
}
RepositoryFile file = pur.getFile(absPath);
if (versionId != null) {
// need to go back to server to get versioned info
file = pur.getFileAtVersion(file.getId(), versionId);
}
// valid file
if (file == null) {
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", absPath));
}
NodeRepositoryFileData data = null;
ObjectRevision revision = null;
// Additional obfuscation through obscurity
data = pur.getDataAtVersionForRead(file.getId(), versionId, NodeRepositoryFileData.class);
revision = getObjectRevision(new StringObjectId(file.getId().toString()), versionId);
TransMeta transMeta = buildTransMeta(file, parentDir, data, revision);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationMetaLoaded.id, transMeta);
return transMeta;
} catch (final KettleException ke) {
// if we have a KettleException, simply re-throw it
throw ke;
} catch (Exception e) {
throw new KettleException("Unable to load transformation from path [" + absPath + "]", e);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-kettle by pentaho.
the class PurRepository method getObjectId.
/**
* Copying the behavior of the original JCRRepository, this implementation returns IDs of deleted objects too.
*/
private ObjectId getObjectId(final String name, final RepositoryDirectoryInterface dir, final RepositoryObjectType objectType, boolean includedDeleteFiles) {
final String absPath = getPath(name, dir, objectType);
RepositoryFile file = pur.getFile(absPath);
if (file != null) {
// file exists
return new StringObjectId(file.getId().toString());
} else if (includedDeleteFiles) {
switch(objectType) {
case DATABASE:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getDatabaseMetaParentFolderPath(), name + RepositoryObjectType.DATABASE.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case TRANSFORMATION:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(dir.getObjectId().getId(), name + RepositoryObjectType.TRANSFORMATION.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case PARTITION_SCHEMA:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getPartitionSchemaParentFolderPath(), name + RepositoryObjectType.PARTITION_SCHEMA.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case SLAVE_SERVER:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getSlaveServerParentFolderPath(), name + RepositoryObjectType.SLAVE_SERVER.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case CLUSTER_SCHEMA:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(getClusterSchemaParentFolderPath(), name + RepositoryObjectType.CLUSTER_SCHEMA.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
case JOB:
{
// file either never existed or has been deleted
List<RepositoryFile> deletedChildren = pur.getDeletedFiles(dir.getObjectId().getId(), name + RepositoryObjectType.JOB.getExtension());
if (!deletedChildren.isEmpty()) {
return new StringObjectId(deletedChildren.get(0).getId().toString());
} else {
return null;
}
}
default:
{
throw new UnsupportedOperationException("not implemented");
}
}
} else {
return null;
}
}
Aggregations