Search in sources :

Example 86 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ModelRepositoryController method getModelsAndDependencies.

private Map<ModelInfo, FileContent> getModelsAndDependencies(Collection<ModelId> modelIds) {
    Map<ModelInfo, FileContent> modelsMap = new HashMap<>();
    if (modelIds != null && !modelIds.isEmpty()) {
        for (ModelId modelId : modelIds) {
            IModelRepository modelRepo = getModelRepository(modelId);
            ModelInfo modelInfo = modelRepo.getById(modelId);
            Optional<FileContent> modelContent = modelRepo.getFileContent(modelId, Optional.empty());
            if (modelContent.isPresent()) {
                modelsMap.put(modelInfo, modelContent.get());
                modelsMap.putAll(getModelsAndDependencies(modelInfo.getReferences()));
            }
        }
    }
    return modelsMap;
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ModelId(org.eclipse.vorto.model.ModelId)

Example 87 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class AbstractRepositoryController method addModelToZip.

protected void addModelToZip(ZipOutputStream zipOutputStream, ModelId modelId) throws Exception {
    try {
        FileContent modelFile = getModelRepository(modelId).getFileContent(modelId, Optional.empty()).get();
        ModelInfo modelResource = getModelRepository(modelId).getById(modelId);
        try {
            ZipEntry zipEntry = new ZipEntry(modelResource.getId().getPrettyFormat() + modelResource.getType().getExtension());
            zipOutputStream.putNextEntry(zipEntry);
            zipOutputStream.write(modelFile.getContent());
            zipOutputStream.closeEntry();
        } catch (Exception ex) {
        // entry possible exists already, so skipping TODO: ugly hack!!
        }
        for (ModelId reference : modelResource.getReferences()) {
            addModelToZip(zipOutputStream, reference);
        }
    } catch (NotAuthorizedException notAuthorized) {
        return;
    }
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ZipEntry(java.util.zip.ZipEntry) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) ModelAlreadyExistsException(org.eclipse.vorto.repository.core.ModelAlreadyExistsException) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) IOException(java.io.IOException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) NewNamespacesNotSupersetException(org.eclipse.vorto.repository.tenant.NewNamespacesNotSupersetException) ModelId(org.eclipse.vorto.model.ModelId)

Example 88 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class TargetPlatformUpgradeTask method doUpgrade.

@Override
public void doUpgrade() throws UpgradeProblem {
    setAdminUserContext();
    List<ModelInfo> searchResult = modelSearchService.search("type:Mapping");
    for (ModelInfo modelInfo : searchResult) {
        logger.info("Upgrading " + modelInfo.toString() + " for target platform key attribute....");
        ModelRepository modelRepository = (ModelRepository) repositoryFactory.getRepositoryByModel(modelInfo.getId());
        ModelResource mappingModel = modelRepository.getEMFResource(modelInfo.getId());
        modelRepository.save(mappingModel, UserContext.user(modelInfo.getAuthor(), modelRepository.getWorkspaceId()));
    }
}
Also used : ModelRepository(org.eclipse.vorto.repository.core.impl.ModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelResource(org.eclipse.vorto.repository.core.ModelResource)

Example 89 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ImportController method doImport.

@RequestMapping(value = "/{handleId:.+}", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('model_creator')")
public ResponseEntity<List<ModelInfo>> doImport(@ApiParam(value = "The file name of uploaded model", required = true) @PathVariable final String handleId, @RequestParam("key") String key, @RequestParam(required = true, value = "targetNamespace") String targetNamespace) {
    LOGGER.info(String.format("Importing Model with handleID %s", handleId));
    try {
        IModelImporter importer = importerService.getImporterByKey(key).get();
        List<ModelInfo> importedModels = importer.doImport(handleId, Context.create(getUserContext(targetNamespace), Optional.of(targetNamespace)));
        for (ModelInfo modelInfo : importedModels) {
            workflowService.start(modelInfo.getId(), getUserContext(targetNamespace));
        }
        return new ResponseEntity<>(importedModels, HttpStatus.OK);
    } catch (Exception e) {
        LOGGER.error(String.format("Error Importing model. %s", handleId), e);
        throw new IllegalArgumentException(String.format("Could not import with handle ID %s", handleId), e);
    }
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ResponseEntity(org.springframework.http.ResponseEntity) IModelImporter(org.eclipse.vorto.repository.importer.IModelImporter) UploadTooLargeException(org.eclipse.vorto.repository.web.core.exceptions.UploadTooLargeException) IOException(java.io.IOException) WorkspaceNotFoundException(org.eclipse.vorto.repository.core.WorkspaceNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)89 Test (org.junit.Test)33 IUserContext (org.eclipse.vorto.repository.core.IUserContext)32 ModelId (org.eclipse.vorto.model.ModelId)28 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)21 FileContent (org.eclipse.vorto.repository.core.FileContent)11 ClassPathResource (org.springframework.core.io.ClassPathResource)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)8 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)8 BeforeClass (org.junit.BeforeClass)7 ResponseEntity (org.springframework.http.ResponseEntity)7 List (java.util.List)6 Optional (java.util.Optional)6 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)6 NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)6 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5