use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.
the class ModelDtoFactory method createResource.
public static Infomodel createResource(InformationModel model, Optional<MappingModel> mappingModel) {
Infomodel infoResource = new Infomodel(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelType.InformationModel);
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()));
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.repository.api.content.Infomodel in project vorto by eclipse.
the class MappingSpecificationBuilder method build.
public IMappingSpecification build() {
try {
Infomodel infomodel = this.repositoryClient.getContent(ModelId.fromPrettyFormat(this.modelId), Infomodel.class, this.targetPlatformKey).get();
DefaultMappingSpecification specification = new DefaultMappingSpecification();
specification.setInfomodel(infomodel);
for (ModelProperty fbProperty : infomodel.getFunctionblocks()) {
ModelId fbModelId = (ModelId) fbProperty.getType();
ModelId mappingId = fbProperty.getMappingReference();
FunctionblockModel fbm;
if (mappingId != null) {
fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, mappingId).get();
} else {
fbm = this.repositoryClient.getContent(fbModelId, FunctionblockModel.class, this.targetPlatformKey).get();
}
if (fbm.getStereotype(STEREOTYPE_FUNCTIONS).isPresent()) {
Stereotype functionsStereotype = fbm.getStereotype(STEREOTYPE_FUNCTIONS).get();
JavascriptFunctions functions = new JavascriptFunctions(fbProperty.getName().toLowerCase());
for (String functionName : functionsStereotype.getAttributes().keySet()) {
if (!"_namespace".equalsIgnoreCase(functionName)) {
functions.addFunction(functionName, functionsStereotype.getAttributes().get(functionName));
}
}
this.library.addFunctions(functions);
}
specification.getFbs().put(fbProperty.getName(), fbm);
}
specification.setLibrary(this.library);
return specification;
} catch (Exception e) {
throw new MappingSpecificationProblem("Problem reading mapping specification", e);
}
}
use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.
the class DefaultMappingClient method newPropertyQuery.
@Override
public IMappingQuery<ModelProperty> newPropertyQuery(IMappedElement element) {
final List<ModelProperty> properties = new ArrayList<ModelProperty>();
if (element instanceof FunctionblockModel) {
FunctionblockModel fbm = (FunctionblockModel) element;
properties.addAll(fbm.getConfigurationProperties());
properties.addAll(fbm.getStatusProperties());
properties.addAll(fbm.getFaultProperties());
} else if (element instanceof Infomodel) {
Infomodel im = (Infomodel) element;
properties.addAll(im.getFunctionblocks());
} else if (element instanceof EntityModel) {
EntityModel entity = (EntityModel) element;
properties.addAll(entity.getProperties());
} else {
throw new UnsupportedOperationException();
}
return new MappingQueryJxPath<ModelProperty>() {
@Override
protected Collection<ModelProperty> getAll() {
return properties;
}
};
}
use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.
the class AbstractDataMapper method map.
public MappedData map(DataInput input, MappingContext mappingContext) {
JXPathContext context = newContext(input.getValue());
context.setFunctions(converterLibrary);
InfomodelData normalized = new InfomodelData();
final Infomodel deviceInfoModel = specification.getInfoModel();
for (ModelProperty fbProperty : deviceInfoModel.getFunctionblocks()) {
if (mappingContext.isIncluded(fbProperty.getName())) {
FunctionblockData mappedFb = mapFunctionBlock(fbProperty, context);
if (mappedFb != null) {
normalized.withFunctionblock(mappedFb);
}
}
}
return this.doMap(normalized, mappingContext);
}
use of org.eclipse.vorto.repository.api.content.Infomodel in project vorto by eclipse.
the class ModelRepositoryClientTest method testGetContentOfSpecificModel.
@Test
public void testGetContentOfSpecificModel() throws Exception {
Infomodel xdkModel = modelRepo.getContent(ModelId.fromPrettyFormat("com.bosch.devices.XDK:1.0.0"), Infomodel.class).get();
assertNotNull(xdkModel);
assertTrue(xdkModel.getFunctionblocks().size() > 0);
}
Aggregations