Search in sources :

Example 11 with ModelResource

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

the class ModelRepositoryController method createVersionOfModel.

@ApiOperation(value = "Creates a new version for the given model in the specified version")
@PreAuthorize("hasAuthority('sysadmin') or (hasAuthority('model_creator') and " + "hasPermission(T(org.eclipse.vorto.model.ModelId).fromPrettyFormat(#modelId)," + "T(org.eclipse.vorto.repository.core.PolicyEntry.Permission).READ))")
@PostMapping(value = "/{modelId:.+}/versions/{modelVersion:.+}", produces = "application/json")
public ResponseEntity<ModelInfo> createVersionOfModel(@ApiParam(value = "modelId", required = true) @PathVariable String modelId, @ApiParam(value = "modelVersion", required = true) @PathVariable String modelVersion) throws WorkflowException {
    final ModelId modelID = ModelId.fromPrettyFormat(modelId);
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    try {
        IUserContext userContext = UserContext.user(authentication, getWorkspaceId(modelId));
        ModelResource resource = getModelRepository(modelID).createVersion(modelID, modelVersion, userContext);
        this.workflowService.start(resource.getId(), userContext);
        return new ResponseEntity<>(resource, HttpStatus.CREATED);
    } catch (FatalModelRepositoryException e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ResponseEntity(org.springframework.http.ResponseEntity) ModelResource(org.eclipse.vorto.repository.core.ModelResource) Authentication(org.springframework.security.core.Authentication) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) ModelId(org.eclipse.vorto.model.ModelId) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with ModelResource

use of org.eclipse.vorto.repository.core.ModelResource 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)

Aggregations

ModelResource (org.eclipse.vorto.repository.core.ModelResource)12 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ArrayList (java.util.ArrayList)4 Model (org.eclipse.vorto.core.api.model.model.Model)4 ModelId (org.eclipse.vorto.model.ModelId)3 ChangeSet (org.eclipse.vorto.model.refactor.ChangeSet)3 IUserContext (org.eclipse.vorto.repository.core.IUserContext)3 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)3 IModelWorkspace (org.eclipse.vorto.utilities.reader.IModelWorkspace)3 ApiOperation (io.swagger.annotations.ApiOperation)2 FileContent (org.eclipse.vorto.repository.core.FileContent)2 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)2 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)2 ResponseEntity (org.springframework.http.ResponseEntity)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 Authentication (org.springframework.security.core.Authentication)2 Injector (com.google.inject.Injector)1 IOException (java.io.IOException)1 ZipInputStream (java.util.zip.ZipInputStream)1 Resource (org.eclipse.emf.ecore.resource.Resource)1