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);
}
}
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;
}
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;
}
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;
}
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)));
}
Aggregations