use of org.eclipse.vorto.repository.domain.Namespace in project vorto by eclipse.
the class ModelRepositoryController method getUserModels.
// ##################### Downloads ################################
@GetMapping(value = { "/mine/download" })
public void getUserModels(Principal principal, final HttpServletResponse response) {
List<ModelId> userModels = Lists.newArrayList();
User user = accountService.getUser(principal.getName());
Collection<Namespace> namespaces = null;
try {
namespaces = userNamespaceRoleService.getNamespaces(user, user);
} catch (OperationForbiddenException | DoesNotExistException e) {
LOGGER.error(e.getMessage(), e);
}
for (Namespace namespace : namespaces) {
IModelRepository modelRepo = getModelRepository(namespace.getWorkspaceId());
List<ModelInfo> modelInfos = modelRepo.search(String.format("author:%s", user.getUsername()));
List<ModelId> modelIds = modelInfos.stream().map(modelInfo -> modelInfo.getId()).collect(Collectors.toList());
userModels.addAll(modelIds);
}
LOGGER.info("Exporting information models for user - results: " + userModels.size());
sendAsZipFile(response, user.getUsername() + "-models.zip", getModelsAndDependencies(userModels));
}
use of org.eclipse.vorto.repository.domain.Namespace in project vorto by eclipse.
the class PayloadMappingController method saveMappingSpecification.
@PutMapping(value = "/{modelId:.+}")
@PreAuthorize("hasAuthority('model_creator')")
public void saveMappingSpecification(@RequestBody MappingSpecification mappingSpecification, @PathVariable String modelId) {
try {
String namespaceName = ModelId.fromPrettyFormat(modelId).getNamespace();
Namespace namespace = namespaceService.getByName(namespaceName);
if (null == namespace) {
LOGGER.error(String.format("Namespace [%s] not found", namespaceName));
return;
}
IUserContext userContext;
if (namespace != null) {
userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication(), namespace.getWorkspaceId());
} else {
userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication());
}
this.mappingService.saveSpecification(mappingSpecification, userContext);
} catch (DoesNotExistException dnee) {
LOGGER.error(dnee);
}
}
use of org.eclipse.vorto.repository.domain.Namespace in project vorto by eclipse.
the class NamespaceRequestCache method namespace.
/**
* Resolves a cached {@link Namespace} by name if applicable.<br/>
* This will also attempt to resolve a "virtual" namespace string, consisting in the real
* namespace appended with an arbitrary number of {@literal .[sub-namespace]} strings to the
* root namespace.<br/>
* The latter is useful when invoking e.g. {@link NamespaceService#getByName(String)} with
* {@link ModelId#getNamespace()} since the latter does not trim out the "virtual" sub-namespaces.
* <br/>
* For instance, when given {@literal com.bosch.iot.suite.example.octopussuiteedition}:
* <ol>
* <li>
* Attempts to resolve {@literal com.bosch.iot.suite.example.octopussuiteedition} and get
* its workspace ID, which fails
* </li>
* <li>
* Attempts to resolve {@literal com.bosch.iot.suite.example} and get its workspace ID, which
* fails again
* </li>
* <li>
* Attempts to resolve {@literal com.bosch.iot.suite} and get its workspace ID, which
* succeeds
* </li>
* </ol>
* Note: virtual namespaces are cached within the scope of a request. <br/>
*
* @param name
* @return
*/
public Optional<Namespace> namespace(String name) {
// boilerplate null/empty checks
if (Objects.isNull(name) || name.trim().isEmpty()) {
return Optional.empty();
}
// lazy population
populateIfEmpty();
// lookup into virtual namespace map first
if (virtualNamespaces.containsKey(name)) {
Namespace result = virtualNamespaces.get(name);
LOGGER.debug(String.format("Resolved virtual namespace [%s] to [%s]", name, result.getName()));
return Optional.of(result);
}
// resolving by name equality
Optional<Namespace> result = this.namespaces.stream().filter(n -> n.getName().equals(name)).findAny();
if (result.isPresent()) {
LOGGER.debug(String.format("Resolved namespace [%s]", name));
return result;
} else {
return resolveVirtualNamespaceRecursively(name, name);
}
}
use of org.eclipse.vorto.repository.domain.Namespace in project vorto by eclipse.
the class BackupRestoreService method restoreRepository.
@Override
public Collection<Namespace> restoreRepository(byte[] backupFile, Predicate<Namespace> namespaceFilter) {
Preconditions.checkNotNull(backupFile, "Backup file must not be null");
try {
Collection<Namespace> namespacesRestored = Lists.newArrayList();
Map<String, byte[]> backups = getBackups(backupFile);
backups.forEach((namespaceName, backup) -> {
LOGGER.info(String.format("Restoring backup for [%s]", namespaceName));
Namespace namespace = namespaceRepository.findByName(namespaceName);
if (null != namespace && namespaceFilter.test(namespace)) {
try {
String workspaceId = namespace.getWorkspaceId();
IRepositoryManager repoMgr = modelRepositoryFactory.getRepositoryManager(workspaceId, authSupplier.get());
if (!repoMgr.exists(workspaceId)) {
repoMgr.createWorkspace(workspaceId);
} else {
repoMgr.removeWorkspace(workspaceId);
repoMgr.createWorkspace(workspaceId);
}
repoMgr.restore(backup);
this.modelRepositoryFactory.getPolicyManager(workspaceId, SecurityContextHolder.getContext().getAuthentication()).restorePolicyEntries();
namespacesRestored.add(namespace);
} catch (Exception e) {
LOGGER.error(String.format("Error while restoring [%s]", namespaceName), e);
}
} else {
LOGGER.info(String.format("Skipping restoration of [%s] either because the namespace could not be found, or was filtered out.", namespaceName));
}
});
if (!namespacesRestored.isEmpty()) {
indexingService.reindexAllModels();
}
return namespacesRestored;
} catch (IOException e) {
throw new GenericApplicationException("Problem while reading zip file during restore", e);
}
}
use of org.eclipse.vorto.repository.domain.Namespace in project vorto by eclipse.
the class NamespaceProvider method mockComNamespace.
public static Namespace mockComNamespace() {
Namespace namespace = new Namespace();
namespace.setName("com");
namespace.setId(2L);
namespace.setWorkspaceId("playground");
return namespace;
}
Aggregations