Search in sources :

Example 6 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelRepositoryController method createModel.

@ApiOperation(value = "Creates a model in the repository with the given model ID and model type.")
@PostMapping(value = "/{modelId:.+}/{modelType}", produces = "application/json")
public ResponseEntity<ModelInfo> createModel(@ApiParam(value = "modelId", required = true) @PathVariable String modelId, @ApiParam(value = "modelType", required = true) @PathVariable ModelType modelType, @RequestBody(required = false) List<ModelProperty> properties) throws WorkflowException {
    final ModelId modelID = ModelId.fromPrettyFormat(modelId);
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    IUserContext userContext = UserContext.user(authentication, getWorkspaceId(modelId));
    IModelRepository modelRepo = getModelRepository(modelID);
    if (modelRepo.exists(modelID)) {
        throw new ModelAlreadyExistsException();
    } else {
        String modelTemplate = null;
        if (modelType == ModelType.InformationModel && properties != null) {
            modelTemplate = new InfomodelTemplate().createModelTemplate(modelID, properties);
        } else {
            modelTemplate = new ModelTemplate().createModelTemplate(modelID, modelType);
        }
        ModelInfo savedModel = modelRepo.save(modelID, modelTemplate.getBytes(), modelID.getName() + modelType.getExtension(), userContext);
        this.workflowService.start(modelID, userContext);
        return new ResponseEntity<>(savedModel, HttpStatus.CREATED);
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelAlreadyExistsException(org.eclipse.vorto.repository.core.ModelAlreadyExistsException) ModelTemplate(org.eclipse.vorto.repository.web.core.templates.ModelTemplate) IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ResponseEntity(org.springframework.http.ResponseEntity) Authentication(org.springframework.security.core.Authentication) InfomodelTemplate(org.eclipse.vorto.repository.web.core.templates.InfomodelTemplate) ModelId(org.eclipse.vorto.model.ModelId) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelDtoFactory method createResource.

private static EntityModel createResource(Entity model, Optional<MappingModel> mappingModel) {
    EntityModel resource = new EntityModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()));
    resource.setDescription(model.getDescription());
    resource.setDisplayName(model.getDisplayname());
    resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
    resource.setProperties(model.getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
    resource.setCategory(model.getCategory());
    if (model.getSuperType() != null)
        resource.setSuperType(new ModelId(model.getSuperType().getName(), model.getSuperType().getNamespace(), model.getSuperType().getVersion()));
    if (mappingModel.isPresent()) {
        resource.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getEntityRule(mappingModel.get().getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                resource.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return resource;
}
Also used : ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) EntityModel(org.eclipse.vorto.model.EntityModel) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.model.ModelId)

Example 8 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelDtoFactory method createResource.

private static Infomodel createResource(InformationModel model, Optional<MappingModel> mappingModel) {
    Infomodel infoResource = new Infomodel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()));
    for (FunctionblockProperty property : model.getProperties()) {
        infoResource.getFunctionblocks().add(createProperty(property, mappingModel));
    }
    infoResource.setDescription(model.getDescription());
    infoResource.setDisplayName(model.getDisplayname());
    infoResource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
    infoResource.setCategory(model.getCategory());
    if (mappingModel.isPresent()) {
        MappingModel _mappingModel = mappingModel.get();
        infoResource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
        for (MappingRule rule : getInfoModelRule(_mappingModel.getRules())) {
            if (rule.getTarget() instanceof StereoTypeTarget) {
                StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
                infoResource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
            } else if (rule.getTarget() instanceof ReferenceTarget) {
                ReferenceTarget target = (ReferenceTarget) rule.getTarget();
                infoResource.setMappingReference(createModelId(target.getMappingModel()));
            }
        }
    }
    return infoResource;
}
Also used : Infomodel(org.eclipse.vorto.model.Infomodel) ReferenceTarget(org.eclipse.vorto.core.api.model.mapping.ReferenceTarget) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.model.ModelId) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 9 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class ModelDtoFactory method createResource.

private static EnumModel createResource(Enum model, Optional<MappingModel> mappingModel) {
    EnumModel resource = new EnumModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()));
    resource.setDescription(model.getDescription());
    resource.setDisplayName(model.getDisplayname());
    resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
    resource.setLiterals(model.getEnums().stream().map(p -> createLiteral(p)).collect(Collectors.toList()));
    resource.setCategory(model.getCategory());
    if (mappingModel.isPresent()) {
        resource.setTargetPlatformKey(mappingModel.get().getTargetPlatform());
        for (MappingRule rule : getEnumRule(mappingModel.get().getRules())) {
            StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
            resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
        }
    }
    return resource;
}
Also used : EnumModel(org.eclipse.vorto.model.EnumModel) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.model.ModelId)

Example 10 with ModelId

use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.

the class AsyncModelMappingsFetcher method run.

@Override
public void run() {
    super.run();
    ModelId id = ModelId.fromPrettyFormat(entry.getKey());
    target.add(ModelMappingDTO.fromModelInfo(entry.getValue(), factory.getRepositoryByModelWithoutSessionHelper(id).getByIdWithPlatformMappings(id)));
}
Also used : ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)124 Test (org.junit.Test)48 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)29 IOException (java.io.IOException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ResponseEntity (org.springframework.http.ResponseEntity)14 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)13 ModelType (org.eclipse.vorto.model.ModelType)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Optional (java.util.Optional)10 List (java.util.List)9 IOUtils (org.apache.commons.io.IOUtils)9 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)9 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)8