Search in sources :

Example 1 with SchemaFileType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType in project midpoint by Evolveum.

the class TestSchemaRestService method assertAndGetPiracySchemaFile.

private SchemaFileType assertAndGetPiracySchemaFile(SchemaFilesType schemas) {
    assertNotNull("Schema file list must no be null", schemas);
    assertEquals(1, schemas.getSchema().size());
    SchemaFileType schemaFile = schemas.getSchema().get(0);
    assertEquals("piracy.xsd", schemaFile.getFileName());
    assertEquals("http://midpoint.evolveum.com/xml/ns/samples/piracy", schemaFile.getNamespace());
    assertEquals(null, schemaFile.getUsualPrefix());
    return schemaFile;
}
Also used : SchemaFileType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType)

Example 2 with SchemaFileType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType in project midpoint-studio by Evolveum.

the class ExtensionSchemaCacheService method refresh.

public void refresh(Environment env) {
    LOG.info("Invoking refresh");
    RunnableUtils.submitNonBlockingReadAction(() -> {
        LOG.info("Refreshing");
        cache.clear();
        if (env == null) {
            LOG.info("Refresh skipped, no environment selected");
            return;
        }
        MidPointClient client = new MidPointClient(project, env, true, true);
        Map<SchemaFileType, String> schemas = client.getExtensionSchemas();
        cache.clear();
        if (schemas != null) {
            for (Map.Entry<SchemaFileType, String> entry : schemas.entrySet()) {
                SchemaFileType schemaFile = entry.getKey();
                VirtualFile file = new LightVirtualFile(schemaFile.getFileName(), entry.getValue());
                PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
                if (!(psiFile instanceof XmlFile)) {
                    continue;
                }
                cache.put(schemaFile.getNamespace(), (XmlFile) psiFile);
            }
        }
        LOG.info("Refresh finished, " + cache.size() + " objects in cache");
    }, AppExecutorUtil.getAppExecutorService());
    LOG.info("Invoke done");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) SchemaFileType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with SchemaFileType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType in project midpoint-studio by Evolveum.

the class TestAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent evt) {
    if (evt.getProject() == null) {
        return;
    }
    // Project project = evt.getProject();
    // 
    // ResourceWizard wizard = ResourceWizard.createWizard(project);
    // wizard.showAndGet();
    RunnableUtils.executeWithPluginClassloader(() -> {
        EnvironmentService es = EnvironmentService.getInstance(evt.getProject());
        MidPointClient client = new MidPointClient(evt.getProject(), es.getSelected(), true, true);
        Map<SchemaFileType, String> result = client.getExtensionSchemas();
        System.out.println(result);
        return result;
    });
}
Also used : MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) SchemaFileType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType) EnvironmentService(com.evolveum.midpoint.studio.impl.EnvironmentService)

Example 4 with SchemaFileType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType in project midpoint by Evolveum.

the class ExtensionSchemaRestController method listSchemas.

@GetMapping
public ResponseEntity<?> listSchemas() {
    Task task = initRequest();
    OperationResult result = createSubresult(task, "listSchemas");
    ResponseEntity<?> response;
    try {
        securityEnforcer.authorize(ModelAuthorizationAction.GET_EXTENSION_SCHEMA.getUrl(), null, AuthorizationParameters.EMPTY, null, task, result);
        SchemaRegistry registry = prismContext.getSchemaRegistry();
        Collection<SchemaDescription> descriptions = registry.getSchemaDescriptions();
        SchemaFilesType files = new SchemaFilesType();
        for (SchemaDescription description : descriptions) {
            String name = computeName(description);
            if (name == null) {
                continue;
            }
            files.schema(new SchemaFileType().namespace(description.getNamespace()).usualPrefix(description.getUsualPrefix()).fileName(name));
        }
        response = ResponseEntity.ok(files);
    } catch (Exception ex) {
        result.recordFatalError(ex);
        response = handleException(result, ex);
    }
    finishRequest(task, result);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SchemaDescription(com.evolveum.midpoint.prism.schema.SchemaDescription) SchemaFilesType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFilesType) SchemaFileType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with SchemaFileType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType in project midpoint by Evolveum.

the class TestSchemaRestService method test020getSchema.

@Test
public void test020getSchema() throws IOException {
    WebClient client = prepareClient();
    when();
    Response response = client.get();
    SchemaFilesType schemas = response.readEntity(SchemaFilesType.class);
    SchemaFileType file = assertAndGetPiracySchemaFile(schemas);
    client.path("/" + file.getFileName());
    client.accept(MediaType.TEXT_PLAIN_TYPE);
    response = client.get();
    then();
    assertStatus(response, 200);
    String content = response.readEntity(String.class);
    String expected = FileUtils.readFileToString(new File("./src/test/resources/schema/piracy.xsd"), StandardCharsets.UTF_8);
    assertEquals("Schemas doesn't match", expected, content);
}
Also used : Response(javax.ws.rs.core.Response) SchemaFilesType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFilesType) SchemaFileType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType) WebClient(org.apache.cxf.jaxrs.client.WebClient) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

SchemaFileType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType)5 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)2 SchemaFilesType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFilesType)2 SchemaDescription (com.evolveum.midpoint.prism.schema.SchemaDescription)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 EnvironmentService (com.evolveum.midpoint.studio.impl.EnvironmentService)1 Task (com.evolveum.midpoint.task.api.Task)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 XmlFile (com.intellij.psi.xml.XmlFile)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 Test (org.testng.annotations.Test)1