use of org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget in project vorto by eclipse.
the class DefaultResolver method doResolve.
@Override
protected ModelId doResolve(ModelInfo mappingModelResource, ResolveQuery query) {
IModelContent content = this.repository.getModelContent(mappingModelResource.getId(), ContentType.DSL);
MappingModel mappingModel = (MappingModel) content.getModel();
Optional<MappingRule> objectRule = mappingModel.getRules().stream().filter(rule -> rule.getTarget() instanceof StereoTypeTarget && ((StereoTypeTarget) rule.getTarget()).getName().equals(query.getStereoType())).findFirst();
if (objectRule.isPresent()) {
Optional<Attribute> objectIdAttribute = ((StereoTypeTarget) objectRule.get().getTarget()).getAttributes().stream().filter(attribute -> attribute.getName().equals(query.getAttributeId())).findFirst();
if (objectIdAttribute.isPresent() && objectIdAttribute.get().getValue().equals(query.getAttributeValue())) {
return ModelId.fromReference(mappingModel.getReferences().get(0).getImportedNamespace(), mappingModel.getReferences().get(0).getVersion());
}
}
return null;
}
use of org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget 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;
}
Aggregations