use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class JcrRepositoryFileDaoIT method testUpdateFile2.
@Test
public // Running without defined date
void testUpdateFile2() throws Exception {
RepositoryFile newFile = createFile("JcrRepositoryFileDaoTest1.test");
IRepositoryFileData dataMock = new SampleRepositoryFileData("", true, 0);
Date startDate = new Date();
newFile = new RepositoryFile.Builder(newFile).createdDate(null).build();
repo.updateFile(newFile, dataMock, "edition #2");
Date finishDate = new Date();
List<VersionSummary> summaries = repo.getVersionSummaries(newFile.getId());
Date lastVersionDate = summaries.get(summaries.size() - 1).getDate();
if (lastVersionDate.before(startDate) || lastVersionDate.after(finishDate)) {
fail("incorrect version date");
}
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method updateFile.
public RepositoryFile updateFile(RepositoryFile file, IRepositoryFileData data, String versionMessage) {
File f = new File(file.getId().toString());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f, false);
if (data instanceof SimpleRepositoryFileData) {
fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
} else if (data instanceof NodeRepositoryFileData) {
fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException(e);
} catch (IOException e) {
throw new UnifiedRepositoryException(e);
} finally {
IOUtils.closeQuietly(fos);
}
return getFile(file.getPath());
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemBackedUnifiedRepository method getDataForReadInBatch.
public <T extends IRepositoryFileData> List<T> getDataForReadInBatch(List<RepositoryFile> files, Class<T> dataClass) {
Assert.notNull(files);
List<T> data = new ArrayList<T>(files.size());
for (RepositoryFile f : files) {
Assert.notNull(f);
data.add(repositoryFileDao.getData(f.getId(), f.getVersionId(), dataClass));
}
return data;
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method createFile.
public RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage) {
String fileNameWithPath = RepositoryFilenameUtils.concat(parentFolderId.toString(), file.getName());
FileOutputStream fos = null;
File f = new File(fileNameWithPath);
try {
f.createNewFile();
fos = new FileOutputStream(f);
if (data instanceof SimpleRepositoryFileData) {
fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
} else if (data instanceof NodeRepositoryFileData) {
fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} catch (IOException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} finally {
IOUtils.closeQuietly(fos);
}
return internalGetFile(f);
}
use of org.pentaho.platform.api.repository2.unified.IRepositoryFileData in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method getData.
@SuppressWarnings("unchecked")
public <T extends IRepositoryFileData> T getData(Serializable fileId, Serializable versionId, Class<T> dataClass) {
File f = new File(fileId.toString());
T data = null;
try {
if (SimpleRepositoryFileData.class.getName().equals(dataClass.getName())) {
data = (T) new SimpleRepositoryFileData(new FileInputStream(f), "UTF-8", "text/plain");
} else if (NodeRepositoryFileData.class.getName().equals(dataClass.getName())) {
throw new UnsupportedOperationException("This operation is not support by this repository");
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException(e);
}
return data;
}
Aggregations