Search in sources :

Example 6 with StereoTypeTarget

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;
}
Also used : IModelContent(org.eclipse.vorto.repository.core.IModelContent) Service(org.springframework.stereotype.Service) ContentType(org.eclipse.vorto.repository.core.IModelRepository.ContentType) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Optional(java.util.Optional) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ResolveQuery(org.eclipse.vorto.repository.api.resolver.ResolveQuery) ModelId(org.eclipse.vorto.repository.api.ModelId) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) IModelContent(org.eclipse.vorto.repository.core.IModelContent) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 7 with StereoTypeTarget

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;
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ModelId(org.eclipse.vorto.repository.api.ModelId) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Aggregations

StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)7 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)6 ModelId (org.eclipse.vorto.repository.api.ModelId)5 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)4 Attribute (org.eclipse.vorto.core.api.model.mapping.Attribute)3 ReferenceTarget (org.eclipse.vorto.core.api.model.mapping.ReferenceTarget)3 Optional (java.util.Optional)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)2 EntityModel (org.eclipse.vorto.repository.api.content.EntityModel)2 Infomodel (org.eclipse.vorto.repository.api.content.Infomodel)2 ModelProperty (org.eclipse.vorto.repository.api.content.ModelProperty)2 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BooleanPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.BooleanPropertyAttribute)1 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)1 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)1 EnumLiteralPropertyAttribute (org.eclipse.vorto.core.api.model.datatype.EnumLiteralPropertyAttribute)1 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)1