use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class DefaultCommentService method createComment.
public void createComment(Comment comment) {
final ModelId id = ModelId.fromPrettyFormat(comment.getModelId());
if (modelRepository.getById(id) != null) {
comment.setModelId(id.getPrettyFormat());
comment.setDate(new Date());
commentRepository.save(comment);
} else {
throw new ModelNotFoundException("Model not found", new PathNotFoundException());
}
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class BulkModelReferencesValidation method validateInZipFiles.
private void validateInZipFiles(ModelInfo modelResource) {
List<ModelId> references = modelResource.getReferences();
List<ModelId> missingReferences = new ArrayList<ModelId>();
for (ModelId modelId : references) {
if (!zipModelIds.contains(modelId)) {
if (isNotInRepository(modelId)) {
missingReferences.add(modelId);
}
}
}
if (missingReferences.size() > 0)
throw new CouldNotResolveReferenceException(modelResource, missingReferences);
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelDtoFactory method createResource.
public static EnumModel createResource(Enum model) {
EnumModel resource = new EnumModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.Datatype);
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()));
return resource;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelDtoFactory method createResource.
public static org.eclipse.vorto.repository.api.content.FunctionblockModel createResource(FunctionblockModel model, Optional<MappingModel> mappingModel) {
org.eclipse.vorto.repository.api.content.FunctionblockModel resource = new org.eclipse.vorto.repository.api.content.FunctionblockModel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.Functionblock);
resource.setDescription(model.getDescription());
resource.setDisplayName(model.getDisplayname());
resource.setReferences(model.getReferences().stream().map(reference -> createModelId(reference)).collect(Collectors.toList()));
if (model.getFunctionblock().getConfiguration() != null) {
resource.setConfigurationProperties(model.getFunctionblock().getConfiguration().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getStatus() != null) {
resource.setStatusProperties(model.getFunctionblock().getStatus().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getFault() != null) {
resource.setFaultProperties(model.getFunctionblock().getFault().getProperties().stream().map(p -> createProperty(p, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getEvents() != null) {
resource.setEvents(model.getFunctionblock().getEvents().stream().map(e -> createEvent(e, mappingModel)).collect(Collectors.toList()));
}
if (model.getFunctionblock().getOperations() != null) {
resource.setOperations(model.getFunctionblock().getOperations().stream().map(o -> createOperation(o)).collect(Collectors.toList()));
}
if (mappingModel.isPresent()) {
MappingModel _mappingModel = mappingModel.get();
resource.setTargetPlatformKey(_mappingModel.getTargetPlatform());
for (MappingRule rule : getFbRule(_mappingModel.getRules())) {
StereoTypeTarget target = (StereoTypeTarget) rule.getTarget();
resource.addStereotype(Stereotype.create(target.getName(), convertAttributesToMap(target.getAttributes())));
}
}
return resource;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryController method getModelContentForTargetPlatform.
@ApiOperation(value = "Returns the model content including target platform specific attributes")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Wrong input"), @ApiResponse(code = 404, message = "Model not found") })
@RequestMapping(value = "/content/{namespace}/{name}/{version:.+}/mapping/{targetplatformKey}", method = RequestMethod.GET)
public AbstractModel getModelContentForTargetPlatform(@ApiParam(value = "The namespace of vorto model, e.g. com.mycompany", required = true) @PathVariable final String namespace, @ApiParam(value = "The name of vorto model, e.g. NewInfomodel", required = true) @PathVariable final String name, @ApiParam(value = "The version of vorto model, e.g. 1.0.0", required = true) @PathVariable final String version, @ApiParam(value = "The key of the targetplatform, e.g. lwm2m", required = true) @PathVariable final String targetplatformKey) {
List<ModelInfo> mappingResource = modelRepository.getMappingModelsForTargetPlatform(new ModelId(name, namespace, version), targetplatformKey);
if (!mappingResource.isEmpty()) {
byte[] mappingContentZip = createZipWithAllDependencies(mappingResource.get(0).getId(), ContentType.DSL);
IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(mappingContentZip))).read();
MappingModel mappingModel = (MappingModel) workspace.get().stream().filter(p -> p instanceof MappingModel).findFirst().get();
byte[] modelContent = createZipWithAllDependencies(new ModelId(name, namespace, version), ContentType.DSL);
workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(new ByteArrayInputStream(modelContent))).read();
return ModelDtoFactory.createResource(workspace.get().stream().filter(p -> p.getName().equals(name)).findFirst().get(), Optional.of(mappingModel));
} else {
return getModelContent(namespace, name, version);
}
}
Aggregations