use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class ModelRepositoryTest method tesUploadValidModel.
@Test
public void tesUploadValidModel() throws IOException {
UploadModelResult uploadResult = modelRepository.upload(IOUtils.toByteArray(new ClassPathResource("sample_models/Color.type").getInputStream()), "Color.type", "admin");
assertEquals(true, uploadResult.isValid());
assertNull(uploadResult.getErrorMessage());
assertNotNull(uploadResult.getHandleId());
ModelInfo resource = uploadResult.getModelResource();
assertEquals("org.eclipse.vorto.examples.type", resource.getId().getNamespace());
assertEquals("Color", resource.getId().getName());
assertEquals("1.0.0", resource.getId().getVersion());
assertEquals(ModelType.Datatype, resource.getType());
assertEquals(0, resource.getReferences().size());
assertEquals("Color", resource.getDisplayName());
assertNull(resource.getDescription());
assertEquals(0, modelRepository.search("*").size());
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class ModelRepositoryTest method testGetReferencedBy.
@Test
public void testGetReferencedBy() throws Exception {
checkinModel("Color.type");
checkinModel("Colorlight.fbmodel");
assertEquals(2, modelRepository.search("*").size());
ModelInfo result = modelRepository.getById(ModelId.fromReference("org.eclipse.vorto.examples.type.Color", "1.0.0"));
assertEquals(1, result.getReferencedBy().size());
assertEquals("org.eclipse.vorto.examples.fb.ColorLight:1.0.0", result.getReferencedBy().get(0).getPrettyFormat());
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class BulkUploadHelper method uploadMultiple.
public List<UploadModelResult> uploadMultiple(byte[] content, String zipFileName, String callerId) {
if (!isValid(zipFileName)) {
throw new FatalModelRepositoryException("Filename/type is invalid", null);
}
List<UploadModelResult> invalidResult = new ArrayList<UploadModelResult>();
List<UploadModelResult> validResult = new ArrayList<UploadModelResult>();
Set<ModelInfo> parsedModels = new HashSet<>();
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(content));
ZipEntry entry = null;
try {
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory()) {
final String fileName = entry.getName();
if (ModelParserFactory.hasParserFor(fileName)) {
try {
parsedModels.add(ModelParserFactory.getParser(fileName).parse(new ByteArrayInputStream(copyStream(zis, entry))));
} catch (ValidationException grammarProblem) {
invalidResult.add(UploadModelResultFactory.create(grammarProblem));
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
try {
List<IModelValidator> bulkUploadValidators = constructBulkUploadValidators(parsedModels);
for (ModelInfo modelResource : parsedModels) {
try {
for (IModelValidator validator : bulkUploadValidators) {
validator.validate(modelResource, InvocationContext.create(callerId));
}
UploadModelResult result = UploadModelResult.valid(modelResource);
if (!invalidResult.contains(result)) {
validResult.add(result);
}
} catch (ValidationException validationException) {
invalidResult.add(UploadModelResultFactory.create(validationException));
}
}
if (invalidResult.isEmpty()) {
DependencyManager dm = new DependencyManager(parsedModels);
return safelyUpload(dm.getSorted());
} else {
List<UploadModelResult> completeResult = new ArrayList<>();
completeResult.addAll(invalidResult);
completeResult.addAll(validResult);
return completeResult;
}
} catch (Exception e) {
throw new FatalModelRepositoryException("Invalid zip file", e);
}
}
use of org.eclipse.vorto.repository.api.ModelInfo in project vorto by eclipse.
the class JcrModelRepository method search.
@Override
public List<ModelInfo> search(final String expression) {
String queryExpression = expression;
if (queryExpression == null || queryExpression.isEmpty()) {
queryExpression = "*";
}
try {
List<ModelInfo> modelResources = new ArrayList<>();
Query query = modelSearchUtil.createQueryFromExpression(session, queryExpression);
logger.debug("Searching repository with expression " + query.getStatement());
QueryResult result = query.execute();
RowIterator rowIterator = result.getRows();
while (rowIterator.hasNext()) {
Row row = rowIterator.nextRow();
Node currentNode = row.getNode();
if (currentNode.hasProperty("vorto:type")) {
try {
modelResources.add(createMinimalModelInfo(currentNode));
} catch (Exception ex) {
// model is corrupt ,ignoring....
}
}
}
return modelResources;
} catch (RepositoryException e) {
throw new RuntimeException("Could not create query manager", e);
}
}
use of org.eclipse.vorto.repository.api.ModelInfo 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;
}
Aggregations