use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelRepositoryTest method testGetModelWithNoImage.
@Test
public void testGetModelWithNoImage() {
checkinModel("Color.type");
checkinModel("Colorlight.fbmodel");
checkinModel("Switcher.fbmodel");
checkinModel("HueLightStrips.infomodel");
assertEquals(false, this.modelRepository.getById(new ModelId("HueLightStrips", "com.mycompany", "1.0.0")).isHasImage());
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class Lwm2mObjectIdResolverTest method testResolveForExistingObjectId.
@Test
public void testResolveForExistingObjectId() {
checkinModel("lwm2m/ColorLight.fbmodel");
checkinModel("lwm2m/ColorLight_lwm2m.mapping");
DefaultResolver lwm2mResolver = new DefaultResolver();
lwm2mResolver.setRepository(this.modelRepository);
assertEquals(new ModelId("ColorLight", "com.mycompany.fb", "1.0.0"), lwm2mResolver.resolve(new LWM2MQuery("2")));
assertNotNull(this.modelRepository.getById(lwm2mResolver.resolve(new LWM2MQuery("2"))));
}
use of org.eclipse.vorto.repository.api.ModelId 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.ModelId in project vorto by eclipse.
the class JcrModelRepository method getMappingModelsForTargetPlatform.
@Override
public List<ModelInfo> getMappingModelsForTargetPlatform(ModelId modelId, String targetPlatform) {
List<ModelInfo> mappingResources = new ArrayList<>();
ModelInfo modelResource = getById(modelId);
if (modelResource != null) {
for (ModelId referenceeModelId : modelResource.getReferencedBy()) {
ModelInfo referenceeModelResources = getById(referenceeModelId);
if (referenceeModelResources.getType() == ModelType.Mapping && isTargetPlatformMapping(referenceeModelResources, targetPlatform)) {
mappingResources.add(referenceeModelResources);
}
}
for (ModelId referencedModelId : modelResource.getReferences()) {
mappingResources.addAll(getMappingModelsForTargetPlatform(referencedModelId, targetPlatform));
}
}
return mappingResources;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class ModelSequencer method execute.
@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
Binary binaryValue = inputProperty.getBinary();
CheckArg.isNotNull(binaryValue, "binary");
ModelInfo modelResource = ModelParserFactory.getParser(outputNode.getPath()).parse(binaryValue.getStream());
outputNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
outputNode.setProperty("vorto:type", modelResource.getType().name());
outputNode.setProperty("vorto:displayname", modelResource.getDisplayName());
outputNode.setProperty("vorto:version", modelResource.getId().getVersion());
outputNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
outputNode.setProperty("vorto:name", modelResource.getId().getName());
ModelReferencesHelper referencesHelper = new ModelReferencesHelper(modelResource.getReferences());
if (referencesHelper.hasReferences()) {
List<Value> references = new ArrayList<Value>();
for (ModelId modelId : referencesHelper.getReferences()) {
ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
Node referencedFolder = outputNode.getSession().getNode(modelIdHelper.getFullPath());
Node reference = referencedFolder.getNodes().nextNode();
references.add(context.valueFactory().createValue(reference));
}
outputNode.setProperty("vorto:references", references.toArray(new Value[references.size()]));
}
return true;
}
Aggregations