Search in sources :

Example 71 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ModelImporterTest method testUploadFileWithoutVortolang.

@Test
public void testUploadFileWithoutVortolang() throws Exception {
    IUserContext alex = createUserContext("alex", "playground");
    UploadModelResult uploadResult = this.importer.upload(FileUpload.create("ColorEnum.type", IOUtils.toByteArray(new ClassPathResource("sample_models/model_without_vortolang.type").getInputStream())), Context.create(alex, Optional.empty()));
    assertEquals(true, uploadResult.isValid());
    List<ModelInfo> imported = this.importer.doImport(uploadResult.getHandleId(), Context.create(alex, Optional.empty()));
    IModelRepository repository = repositoryFactory.getRepository(alex);
    String content = new String(repository.getFileContent(imported.get(0).getId(), Optional.empty()).get().getContent(), "utf-8");
    System.out.println(content);
    assertTrue(content.contains("vortolang 1.0"));
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 72 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class GeneralSearchTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    testInfrastructure = new SearchTestInfrastructure();
    ModelInfo datatype = testInfrastructure.importModel("Color.type", testInfrastructure.getDefaultUser());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) BeforeClass(org.junit.BeforeClass)

Example 73 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class DefaultGeneratorPluginService method doGenerateWithApiVersion1.

private GeneratedOutput doGenerateWithApiVersion1(ModelInfo modelInfo, String serviceKey, Map<String, String> requestParams, String baseUrl) {
    if (modelInfo == null) {
        throw new ModelNotFoundException("Model with the given ID does not exist", null);
    }
    if (modelInfo.getType() == ModelType.Datatype || modelInfo.getType() == ModelType.Mapping) {
        throw new GenerationException("Provided model is neither an information model nor a function block model!");
    }
    HttpEntity<String> entity = getUserToken().map(token -> {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Authorization", "Bearer " + token);
        return new HttpEntity<>("parameters", headers);
    }).orElse(null);
    ModelId modelId = modelInfo.getId();
    ResponseEntity<byte[]> response = restTemplate.exchange(baseUrl + "/rest/generators/{pluginkey}/generate/{namespace}/{name}/{version}" + attachRequestParams(requestParams), HttpMethod.GET, entity, byte[].class, serviceKey, modelId.getNamespace(), modelId.getName(), modelId.getVersion());
    return new GeneratedOutput(response.getBody(), extractFileNameFromHeader(response), response.getHeaders().getContentLength());
}
Also used : Arrays(java.util.Arrays) GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException) IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) IGeneratorPluginService(org.eclipse.vorto.repository.plugin.generator.IGeneratorPluginService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ModelIdToModelContentConverter(org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter) ArrayList(java.util.ArrayList) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Service(org.springframework.stereotype.Service) Map(java.util.Map) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) IModelRepositoryFactory(org.eclipse.vorto.repository.core.IModelRepositoryFactory) RestTemplate(org.springframework.web.client.RestTemplate) OAuth2AuthenticationDetails(org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) HttpHeaders(org.springframework.http.HttpHeaders) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(org.springframework.http.HttpMethod) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ModelId(org.eclipse.vorto.model.ModelId) ModelType(org.eclipse.vorto.model.ModelType) GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration) List(java.util.List) ModelContent(org.eclipse.vorto.model.ModelContent) HttpEntity(org.springframework.http.HttpEntity) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) Comparator(java.util.Comparator) Authentication(org.springframework.security.core.Authentication) GeneratorPluginInfo(org.eclipse.vorto.plugin.generator.GeneratorPluginInfo) HttpHeaders(org.springframework.http.HttpHeaders) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) GeneratedOutput(org.eclipse.vorto.repository.plugin.generator.GeneratedOutput) GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException) ModelId(org.eclipse.vorto.model.ModelId)

Example 74 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class DefaultGeneratorPluginService method generate.

@Override
public GeneratedOutput generate(IUserContext userContext, ModelId modelId, String serviceKey, Map<String, String> requestParams) {
    incrementMetric(serviceKey);
    IModelRepository repository = modelRepositoryFactory.getRepositoryByModel(modelId);
    ModelInfo modelInfo = repository.getById(modelId);
    GeneratorPluginConfiguration plugin = getPluginInfo(serviceKey, false);
    if (modelInfo.isReleased() && hasGeneratorProductionTag(plugin)) {
        return generatedOutputAttachmentHandler.getGeneratedOutputFromAttachment(modelInfo, requestParams, plugin, repository).orElseGet(() -> generateAndAttachOutput(userContext, modelInfo, serviceKey, requestParams, plugin));
    }
    return doGenerate(modelInfo, serviceKey, requestParams, plugin);
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) GeneratorPluginConfiguration(org.eclipse.vorto.repository.plugin.generator.GeneratorPluginConfiguration)

Example 75 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class RemoteImporter method validate.

@Override
protected List<ValidationReport> validate(FileUpload fileUpload, Context context) {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
    body.add("file", new FileContentResource(fileUpload));
    HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
    ResponseEntity<org.eclipse.vorto.plugin.importer.ValidationReport> validationResult = restTemplate.postForEntity(this.endpointUrl + "/api/2/plugins/importers/{pluginkey}/file_validation", requestEntity, org.eclipse.vorto.plugin.importer.ValidationReport.class, this.info.getKey());
    org.eclipse.vorto.plugin.importer.ValidationReport result = validationResult.getBody();
    if (result.isValid()) {
        ModelInfo modelInfo = new ModelInfo(new ModelId(fileUpload.getName(), context.getTargetNamespace().get(), "1.0.0"), org.eclipse.vorto.model.ModelType.Functionblock);
        ValidationReport report = modelValidationHelper.validateModelCreation(modelInfo, context.getUser());
        return Arrays.asList(report);
    } else {
        return Arrays.asList(ValidationReport.invalid(result.getMessage()));
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ValidationReport(org.eclipse.vorto.repository.importer.ValidationReport) FileContentResource(org.eclipse.vorto.repository.plugin.FileContentResource) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)89 Test (org.junit.Test)33 IUserContext (org.eclipse.vorto.repository.core.IUserContext)32 ModelId (org.eclipse.vorto.model.ModelId)28 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)21 FileContent (org.eclipse.vorto.repository.core.FileContent)11 ClassPathResource (org.springframework.core.io.ClassPathResource)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)8 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)8 BeforeClass (org.junit.BeforeClass)7 ResponseEntity (org.springframework.http.ResponseEntity)7 List (java.util.List)6 Optional (java.util.Optional)6 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)6 NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)6 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5