use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class AbstractModelParser method parseModelIdFromFileName.
private ModelId parseModelIdFromFileName() {
String pureFileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.lastIndexOf("."));
ModelId modelId = new ModelId();
try {
modelId.setNamespace(pureFileName.substring(0, pureFileName.lastIndexOf(".")));
modelId.setName(pureFileName.substring(pureFileName.lastIndexOf(".") + 1, pureFileName.indexOf("_")));
String version = pureFileName.substring(pureFileName.indexOf("_") + 1);
version = version.replaceAll("_", ".");
modelId.setVersion(version.substring(0, 5));
} catch (Throwable t) {
return new ModelId(pureFileName, "", "0.0.0");
}
return modelId;
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class DataValidation method main.
public static void main(String[] args) {
ModelId presenceCapability = ModelId.fromPrettyFormat("com.ipso.smartobjects.Presence:0.0.1");
JSONObject jsonSchema = getSchemaForCapability(presenceCapability);
JSONObject jsonInput = getJsonInput();
Schema schema = SchemaLoader.load(jsonSchema);
try {
schema.validate(jsonInput);
System.out.println("Congrats. The JSON is valid");
} catch (ValidationException validationException) {
System.err.println("JSON is not valid according to schema");
validationException.printStackTrace();
}
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class DefaultModelPublisher method publish.
@Override
public ModelId publish(ModelType type, String content) throws ModelPublishException {
String uploadModelsUrl = String.format("%s/rest/secure", getRequestContext().getBaseUrl());
HttpPost query = new HttpPost(uploadModelsUrl);
HttpEntity entity = MultipartEntityBuilder.create().addPart("fileName", new StringBody("vortomodel" + type.getExtension(), ContentType.DEFAULT_TEXT)).addPart("fileDescription", new StringBody("", ContentType.DEFAULT_TEXT)).addPart("file", new ByteArrayBody(content.getBytes(), ContentType.APPLICATION_OCTET_STREAM, "vortomodel" + type.getExtension())).build();
query.setEntity(entity);
try {
CompletableFuture<UploadModelResponse> response = execute(query, new TypeToken<UploadModelResponse>() {
}.getType());
List<UploadModelResult> result = response.get().getObj();
if (response.get().getIsSuccess()) {
String checkinModelUrl = String.format("%s/rest/secure/%s", getRequestContext().getBaseUrl(), result.get(0).getHandleId());
HttpPut checkInModel = new HttpPut(checkinModelUrl);
CompletableFuture<ModelId> checkedInResult = execute(checkInModel, new TypeToken<ModelId>() {
}.getType());
return (ModelId) checkedInResult.get();
} else {
throw new ModelPublishException(result.get(0));
}
} catch (Throwable ex) {
if (!(ex instanceof ModelPublishException)) {
throw new RuntimeException(ex);
} else {
throw ((ModelPublishException) ex);
}
}
}
use of org.eclipse.vorto.repository.api.ModelId in project vorto by eclipse.
the class JcrModelRepository method createModelResource.
private ModelInfo createModelResource(Node node) throws RepositoryException {
ModelInfo resource = createMinimalModelInfo(node);
if (node.hasProperty("vorto:references")) {
Value[] referenceValues = null;
try {
referenceValues = node.getProperty("vorto:references").getValues();
} catch (Exception ex) {
referenceValues = new Value[] { node.getProperty("vorto:references").getValue() };
}
if (referenceValues != null) {
ModelReferencesHelper referenceHelper = new ModelReferencesHelper();
for (Value referValue : referenceValues) {
String nodeUuid = referValue.getString();
Node referencedNode = session.getNodeByIdentifier(nodeUuid);
referenceHelper.addModelReference(ModelIdHelper.fromPath(referencedNode.getParent().getPath()).getPrettyFormat());
}
resource.setReferences(referenceHelper.getReferences());
}
}
PropertyIterator propIter = node.getReferences();
while (propIter.hasNext()) {
Property prop = propIter.nextProperty();
Node referencedByFileNode = prop.getParent();
final ModelId referencedById = ModelIdHelper.fromPath(referencedByFileNode.getParent().getPath());
resource.getReferencedBy().add(referencedById);
if (referencedByFileNode.getName().endsWith(ModelType.Mapping.getExtension())) {
ModelEMFResource emfResource = getEMFResource(referencedById);
resource.addPlatformMapping(emfResource.getTargetPlatform(), referencedById);
}
}
return resource;
}
use of org.eclipse.vorto.repository.api.ModelId 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;
}
Aggregations