use of org.pentaho.platform.api.repository2.unified.RepositoryFile 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.platform.api.repository2.unified.RepositoryFile 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);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-metaverse by pentaho.
the class LocatorTestUtils method createFileTree.
private static RepositoryFileTree createFileTree(File root) {
RepositoryFile repFile = new RepositoryFile(root.getPath(), root.getName(), root.isDirectory(), false, false, null, root.getAbsolutePath(), new Date(root.lastModified()), new Date(root.lastModified()), false, null, null, null, null, root.getName(), null, null, null, root.length(), "Admin", null);
List<RepositoryFileTree> children = new ArrayList<RepositoryFileTree>();
File[] files = root.listFiles();
for (File file : files) {
if (file.isHidden()) {
continue;
}
if (file.isDirectory()) {
RepositoryFileTree kid = createFileTree(file);
children.add(kid);
} else if (file.isFile()) {
RepositoryFile kid = new RepositoryFile(file.getPath(), file.getName(), file.isDirectory(), false, false, null, file.getPath(), new Date(file.lastModified()), new Date(file.lastModified()), false, null, null, null, null, file.getName(), null, null, null, root.length(), "Admin", null);
RepositoryFileTree kidTree = new RepositoryFileTree(kid, null);
children.add(kidTree);
}
}
RepositoryFileTree fileTree = new RepositoryFileTree(repFile, children);
return fileTree;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-metaverse by pentaho.
the class RepositoryLocatorTest method setUp.
@Before
public void setUp() throws Exception {
RepositoryLocator loc = new RepositoryLocator() {
@Override
protected IUnifiedRepository getUnifiedRepository(IPentahoSession session) throws Exception {
return null;
}
@Override
protected Object getContents(RepositoryFile locatedItem) throws Exception {
return null;
}
/**
* Returns the locator node for this locator. The locator node is the node in the metaverse
* that represents this locator. It is used to create a link from this locator to the documents
* that are found by/within it.
*
* @return The locator node in the metaverse
*/
@Override
public IMetaverseNode getLocatorNode() {
return new MetaverseNode(mock(Vertex.class));
}
@Override
public URI getRootUri() {
return null;
}
};
loc.setMetaverseBuilder(metaverseBuilder);
baseLocator = spy(loc);
when(baseLocator.getMetaverseBuilder()).thenReturn(metaverseBuilder);
when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(metaverseObjectFactory);
when(metaverseObjectFactory.createDocumentObject()).thenReturn(new MetaverseDocument());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class PentahoPlatformExporter method exportFileContent.
protected void exportFileContent(RepositoryFile exportRepositoryFile) throws IOException, ExportException {
// get the file path
String filePath = new File(this.path).getParent();
if (filePath == null) {
filePath = "/";
}
// send a response right away if not found
if (exportRepositoryFile == null) {
// todo: add to messages.properties
throw new FileNotFoundException("JCR file not found: " + this.path);
}
if (exportRepositoryFile.isFolder()) {
// Handle recursive export
getExportManifest().getManifestInformation().setRootFolder(path.substring(0, path.lastIndexOf("/") + 1));
// don't zip root folder without name
if (!ClientRepositoryPaths.getRootFolderPath().equals(exportRepositoryFile.getPath())) {
zos.putNextEntry(new ZipEntry(getFixedZipEntryName(exportRepositoryFile, filePath)));
}
exportDirectory(exportRepositoryFile, zos, filePath);
} else {
getExportManifest().getManifestInformation().setRootFolder(path.substring(0, path.lastIndexOf("/") + 1));
exportFile(exportRepositoryFile, zos, filePath);
}
}
Aggregations