use of org.uberfire.java.nio.file.attribute.FileTime in project kie-wb-common by kiegroup.
the class LibraryServiceImpl method getProjectAssets.
@Override
public AssetQueryResult getProjectAssets(final ProjectAssetsQuery query) {
checkNotNull("query", query);
final boolean projectStillExists = ioService.exists(Paths.convert(query.getProject().getBranch().getPath()));
if (!projectStillExists) {
return AssetQueryResult.nonexistent();
} else if (!indexOracle.isIndexed(query.getProject())) {
return AssetQueryResult.unindexed();
}
final HashSet<ValueIndexTerm> queryTerms = buildProjectAssetsQuery(query);
final PageResponse<RefactoringPageRow> findRulesByProjectQuery = refactoringQueryService.query(new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, queryTerms, query.getStartIndex(), query.getAmount(), Boolean.TRUE));
final List<FolderItem> assets = findRulesByProjectQuery.getPageRowList().stream().map(row -> {
final Path path = (Path) row.getValue();
return new FolderItem(path, path.getFileName(), FolderItemType.FILE, false, Paths.readLockedBy(path), Collections.<String>emptyList(), explorerServiceHelper.getRestrictedOperations(path));
}).collect(Collectors.toList());
return AssetQueryResult.normal(assets.stream().map(asset -> {
AssetInfo info = null;
try {
final Map<String, Object> attributes = ioService.readAttributes(Paths.convert((Path) asset.getItem()));
final FileTime lastModifiedFileTime = (FileTime) getAttribute(LibraryService.LAST_MODIFIED_TIME, attributes).get();
final FileTime createdFileTime = (FileTime) getAttribute(LibraryService.CREATED_TIME, attributes).get();
final Date lastModifiedTime = new Date(lastModifiedFileTime.toMillis());
final Date createdTime = new Date(createdFileTime.toMillis());
info = new AssetInfo(asset, lastModifiedTime, createdTime);
} catch (NoSuchFileException nfe) {
log.debug("File '" + asset.getFileName() + "' in LibraryIndex but not VFS. Suspected deletion. Skipping.");
}
return Optional.ofNullable(info);
}).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
}
Aggregations