use of io.lumeer.core.auth.AuthenticatedUser in project engine by Lumeer.
the class ProjectFacade method getRawProjectContent.
public ProjectContent getRawProjectContent(final Project project) {
if (!project.isPublic() && !permissionsChecker.canReadAllInWorkspace()) {
throw new NoResourcePermissionException(project);
}
final ProjectContent content = new ProjectContent();
content.setCollections(collectionDao.getAllCollections().stream().map(CollectionWithId::new).collect(Collectors.toList()));
content.setViews(viewDao.getAllViews().stream().map(ViewWithId::new).collect(Collectors.toList()));
content.setLinkTypes(linkTypeDao.getAllLinkTypes().stream().map(LinkTypeWithId::new).collect(Collectors.toList()));
String userId = Utils.computeIfNotNull(authenticatedUser, AuthenticatedUser::getCurrentUserId);
if (userId != null) {
content.setFavoriteCollectionIds(favoriteItemDao.getFavoriteCollectionIds(userId, project.getId()));
content.setFavoriteViewIds(favoriteItemDao.getFavoriteViewIds(userId, project.getId()));
} else {
content.setFavoriteCollectionIds(favoriteItemDao.getFavoriteCollectionIds(project.getId()));
content.setFavoriteViewIds(favoriteItemDao.getFavoriteViewIds(project.getId()));
}
content.setSequences(sequenceDao.getAllSequences());
content.setSelectionLists(selectionListDao.getAllLists(List.of(project.getId())));
final List<LinkInstanceWithId> linkInstances = new ArrayList<>();
final Map<String, List<DataDocument>> linksData = new HashMap<>();
content.getLinkTypes().forEach(lt -> {
linksData.put(lt.getId(), linkDataDao.getDataStream(lt.getId()).map(this::translateDataDocument).collect(Collectors.toList()));
linkInstances.addAll(linkInstanceDao.getLinkInstancesByLinkType(lt.getId()).stream().map(LinkInstanceWithId::new).collect(Collectors.toList()));
});
content.setLinkInstances(linkInstances);
content.setLinkData(linksData);
final List<DocumentWithId> documents = new ArrayList<>();
final Map<String, List<DataDocument>> documentsData = new HashMap<>();
content.getCollections().forEach(c -> {
documentsData.put(c.getId(), dataDao.getDataStream(c.getId()).map(this::translateDataDocument).collect(Collectors.toList()));
documents.addAll(documentDao.getDocumentsByCollection(c.getId()).stream().map(DocumentWithId::new).collect(Collectors.toList()));
});
content.setDocuments(documents);
content.setData(documentsData);
content.setComments(resourceCommentDao.getAllComments().stream().map(ResourceCommentWrapper::new).collect(Collectors.toList()));
if (permissionsChecker.hasRole(project, RoleType.TechConfig)) {
content.setVariables(resourceVariableDao.getInProject(getOrganization().getId(), project.getId()).stream().filter(variable -> !variable.getSecure()).collect(Collectors.toList()));
}
content.setTemplateMeta(new ProjectMeta(project.getCode(), content.getCollections().size(), content.getLinkTypes().size(), content.getViews().size(), content.getDocuments().size()));
return content;
}
Aggregations