use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class VisibilitySearchSimpleTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
testInfrastructure = new SearchTestInfrastructure();
testInfrastructure.importModel(testInfrastructure.DATATYPE_MODEL);
List<ModelInfo> model = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).search("*");
// this is arguably over-cautious, as the next statement would fail all tests anyway
if (model.isEmpty()) {
fail("Model is empty after importing.");
}
// "alex" user updates the only imported model's visibility to public
ModelId updated = testInfrastructure.getRepositoryFactory().getRepository(testInfrastructure.createUserContext("alex")).updateVisibility(model.get(0).getId(), "Public");
// importing another model as private
testInfrastructure.importModel(testInfrastructure.INFORMATION_MODEL, testInfrastructure.createUserContext("alex", "playground"));
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelPolicyManager method restorePolicyEntriesInternal.
/**
* Restores the access policies. (https://github.com/eclipse/vorto/issues/2350)
*
* @param session
* @throws RepositoryException
*/
private void restorePolicyEntriesInternal(Session session) {
LOGGER.info("restorePolicyEntries");
if (this.modelRepositoryFactory == null) {
return;
}
IModelRepository repo = this.modelRepositoryFactory.getRepository(session.getWorkspace().getName());
List<ModelInfo> modelList = repo.search("");
Map<String, IWorkflowFunction[]> stateToFunctionsMap = createStateToFunctionsMap();
for (ModelInfo model : modelList) {
applyWorkflowFunctions(model, session, stateToFunctionsMap);
setVisibility(model);
}
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelRepositoryEventListener method makeModelsAnonymous.
private void makeModelsAnonymous(AppEvent event) {
String username = (String) event.getSubject();
IUserContext technicalUserContext = PrivilegedUserContextProvider.systemAdminContext(USER_ADMIN);
List<ModelInfo> result = searchService.search("userReference:" + username, technicalUserContext);
result.forEach(model -> {
IModelRepository repository = repositoryFactory.getRepositoryByModel(model.getId(), technicalUserContext);
if (model.getAuthor() != null && model.getAuthor().equals(username)) {
model.setAuthor(User.USER_ANONYMOUS);
}
Map<String, String> properties = new HashMap<>();
properties.put(VORTO_AUTHOR, User.USER_ANONYMOUS);
repository.updatePropertyInElevatedSession(model.getId(), properties, technicalUserContext);
});
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class DefaultCommentService method notifyAllCommentAuthors.
private void notifyAllCommentAuthors(Comment comment, ModelInfo model) {
Set<String> recipients = new HashSet<>();
recipients.add(model.getAuthor());
List<Comment> existingComments = this.commentRepository.findByModelId(comment.getModelId());
for (Comment c : existingComments) {
recipients.add(c.getAuthor());
}
recipients.stream().filter(recipient -> !User.USER_ANONYMOUS.equalsIgnoreCase(recipient)).forEach(recipient -> {
User user = accountService.getUser(recipient);
if (user != null) {
notificationService.sendNotification(new CommentReplyMessage(user, model, comment.getContent()));
}
});
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelIdToModelContentConverter method convert.
@Override
public ModelContent convert(ModelId modelId, Optional<String> platformKey) {
modelId = repositoryFactory.getRepositoryByNamespace(modelId.getNamespace()).getLatestModelVersionIfLatestTagIsSet(modelId);
if (!repositoryFactory.getRepositoryByModel(modelId).exists(modelId)) {
throw new ModelNotFoundException(String.format("Model [%s] does not exist", modelId.getPrettyFormat()), null);
}
ModelWorkspaceReader workspaceReader = getWorkspaceForModel(modelId);
ModelContent result = new ModelContent();
result.setRoot(modelId);
if (platformKey.isPresent()) {
final List<ModelInfo> mappingResources = repositoryFactory.getRepositoryByModel(modelId).getMappingModelsForTargetPlatform(modelId, platformKey.get(), Optional.empty());
if (!mappingResources.isEmpty()) {
// adding to workspace reader in order to resolve cross linking between mapping models correctly
mappingResources.forEach(mapping -> workspaceReader.addFile(new ByteArrayInputStream(repositoryFactory.getRepositoryByModel(mapping.getId()).getFileContent(mapping.getId(), Optional.empty()).get().getContent()), org.eclipse.vorto.model.ModelType.Mapping));
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
Optional<MappingModel> mappingModel = getMappingModelForModel(mappingResources, model);
if (mappingModel.isPresent()) {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), mappingModel);
createdModel.setTargetPlatformKey(platformKey.get());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
} else {
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty()));
}
});
} else {
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
createdModel.setTargetPlatformKey(platformKey.get());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
});
}
} else {
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
});
}
return result;
}
Aggregations