Search in sources :

Example 6 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class TaskUpgradeTask method processObject.

@Override
public ProcessObjectResult processObject(MidPointObject object) throws Exception {
    String oldContent = object.getContent();
    String newContent = MidPointUtils.upgradeTaskToUseActivities(oldContent);
    MidPointObject newObject = MidPointObject.copy(object);
    newObject.setContent(newContent);
    return new ProcessObjectResult(null).object(newObject);
}
Also used : MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) ProcessObjectResult(com.evolveum.midpoint.studio.action.transfer.ProcessObjectResult)

Example 7 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class ConnectorXmlSchemaCacheService method buildConnectorSchema.

private XmlFile buildConnectorSchema(MidPointObject object) {
    String connector = object.getContent();
    Element xsdSchema = getXsdSchema(connector);
    List<Element> elements = DOMUtil.getChildElements(xsdSchema, new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "element"));
    Optional<Element> connectorConfiguration = elements.stream().filter(e -> "connectorConfiguration".equals(DOMUtil.getAttribute(e, "name"))).findFirst();
    connectorConfiguration.ifPresent(e -> xsdSchema.removeChild(e));
    List<Element> complexTypes = DOMUtil.getChildElements(xsdSchema, new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "complexType"));
    Optional<Element> complexConfigurationType = complexTypes.stream().filter(e -> "ConfigurationType".equals(DOMUtil.getAttribute(e, "name"))).findFirst();
    complexConfigurationType.ifPresent(e -> xsdSchema.removeChild(e));
    Optional<Element> complexConfigurationPropertiesType = complexTypes.stream().filter(e -> "ConfigurationPropertiesType".equals(DOMUtil.getAttribute(e, "name"))).findFirst();
    complexConfigurationPropertiesType.ifPresent(e -> {
        Element sequence = DOMUtil.getChildElement(e, new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "sequence"));
        if (sequence == null) {
            return;
        }
        List<Element> list = DOMUtil.getChildElements(sequence, new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "element"));
        for (Element element : list) {
            Element cloned = (Element) element.cloneNode(true);
            cloned.removeAttribute("minOccurs");
            cloned.removeAttribute("maxOccurs");
            xsdSchema.appendChild(cloned);
        }
    });
    complexConfigurationPropertiesType.ifPresent(e -> xsdSchema.removeChild(e));
    String xsd = DOMUtil.serializeDOMToString(xsdSchema);
    return (XmlFile) PsiFileFactory.getInstance(project).createFileFromText("connector-" + object.getOid() + "-schema-modified.xsd", XMLLanguage.INSTANCE, xsd);
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) XmlFile(com.intellij.psi.xml.XmlFile) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RunnableUtils(com.evolveum.midpoint.studio.util.RunnableUtils) XMLLanguage(com.intellij.lang.xml.XMLLanguage) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) Environment(com.evolveum.midpoint.studio.impl.Environment) DOMUtil(com.evolveum.midpoint.util.DOMUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SchemaConstantsGenerated(com.evolveum.midpoint.schema.SchemaConstantsGenerated) PrismContext(com.evolveum.midpoint.prism.PrismContext) Document(org.w3c.dom.Document) Map(java.util.Map) Project(com.intellij.openapi.project.Project) AppExecutorUtil(com.intellij.util.concurrency.AppExecutorUtil) Logger(com.intellij.openapi.diagnostic.Logger) XMLConstants(javax.xml.XMLConstants) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ClientUtils(com.evolveum.midpoint.studio.client.ClientUtils) SearchResult(com.evolveum.midpoint.studio.client.SearchResult) XmlTag(com.intellij.psi.xml.XmlTag) PrismParser(com.evolveum.midpoint.prism.PrismParser) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PrismObject(com.evolveum.midpoint.prism.PrismObject) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) Collectors(java.util.stream.Collectors) MidPointUtils(com.evolveum.midpoint.studio.util.MidPointUtils) MatchingRuleRegistryFactory(com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) List(java.util.List) Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) Optional(java.util.Optional) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) XmlFile(com.intellij.psi.xml.XmlFile) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element)

Example 8 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class ConnectorXmlSchemaCacheService method buildIcfSchema.

private XmlFile buildIcfSchema(MidPointObject object) {
    String connector = object.getContent();
    Element xsdSchema = getXsdSchema(connector);
    List<Element> complexTypes = DOMUtil.getChildElements(xsdSchema, new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "complexType"));
    Optional<Element> complexConfigurationPropertiesType = complexTypes.stream().filter(e -> "ConfigurationPropertiesType".equals(DOMUtil.getAttribute(e, "name"))).findFirst();
    String importNamespace = xsdSchema.getAttribute("targetNamespace");
    Document doc = DOMUtil.getDocument(DOMUtil.XSD_SCHEMA_ELEMENT);
    Element schema = doc.getDocumentElement();
    schema.setAttribute("xmlns:a", SchemaConstantsGenerated.NS_ANNOTATION);
    schema.setAttribute("xmlns:icfc", SchemaConstantsGenerated.NS_ICF_CONFIGURATION);
    schema.setAttribute("xmlns:con", importNamespace);
    schema.setAttribute("targetNamespace", SchemaConstantsGenerated.NS_ICF_CONFIGURATION);
    schema.setAttribute("elementFormDefault", "qualified");
    Element _import = DOMUtil.createElement(doc, xsdElement("import"));
    _import.setAttribute("namespace", importNamespace);
    schema.appendChild(_import);
    Element element = DOMUtil.createElement(doc, xsdElement("element"));
    element.setAttribute("name", "configurationProperties");
    element.setAttribute("type", "icfc:ConfigurationPropertiesType");
    schema.appendChild(element);
    Element complex = DOMUtil.createElement(doc, xsdElement("complexType"));
    complex.setAttribute("name", "ConfigurationPropertiesType");
    schema.appendChild(complex);
    Element sequence = DOMUtil.createElement(doc, xsdElement("sequence"));
    complex.appendChild(sequence);
    complexConfigurationPropertiesType.ifPresent(e -> {
        Element seq = DOMUtil.getChildElement(e, new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "sequence"));
        if (seq == null) {
            return;
        }
        List<Element> list = DOMUtil.getChildElements(seq, new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "element"));
        for (Element el : list) {
            Element cloned = (Element) el.cloneNode(true);
            cloned.setAttribute("ref", "con:" + cloned.getAttribute("name"));
            cloned.removeAttribute("name");
            cloned.removeAttribute("type");
            sequence.appendChild(doc.adoptNode(cloned));
        }
    });
    String xsd = DOMUtil.serializeDOMToString(doc);
    return (XmlFile) PsiFileFactory.getInstance(project).createFileFromText("connector-" + object.getOid() + "-schema.xsd", XMLLanguage.INSTANCE, xsd);
}
Also used : PsiFileFactory(com.intellij.psi.PsiFileFactory) XmlFile(com.intellij.psi.xml.XmlFile) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RunnableUtils(com.evolveum.midpoint.studio.util.RunnableUtils) XMLLanguage(com.intellij.lang.xml.XMLLanguage) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) Environment(com.evolveum.midpoint.studio.impl.Environment) DOMUtil(com.evolveum.midpoint.util.DOMUtil) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SchemaConstantsGenerated(com.evolveum.midpoint.schema.SchemaConstantsGenerated) PrismContext(com.evolveum.midpoint.prism.PrismContext) Document(org.w3c.dom.Document) Map(java.util.Map) Project(com.intellij.openapi.project.Project) AppExecutorUtil(com.intellij.util.concurrency.AppExecutorUtil) Logger(com.intellij.openapi.diagnostic.Logger) XMLConstants(javax.xml.XMLConstants) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ClientUtils(com.evolveum.midpoint.studio.client.ClientUtils) SearchResult(com.evolveum.midpoint.studio.client.SearchResult) XmlTag(com.intellij.psi.xml.XmlTag) PrismParser(com.evolveum.midpoint.prism.PrismParser) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PrismObject(com.evolveum.midpoint.prism.PrismObject) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) Collectors(java.util.stream.Collectors) MidPointUtils(com.evolveum.midpoint.studio.util.MidPointUtils) MatchingRuleRegistryFactory(com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) List(java.util.List) Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) Optional(java.util.Optional) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) XmlFile(com.intellij.psi.xml.XmlFile) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 9 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class ConnectorXmlSchemaCacheService method refresh.

private 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);
        SearchResult result = client.search(ConnectorType.class, null, true);
        for (MidPointObject object : result.getObjects()) {
            try {
                PrismObject<?> prismObject = client.parseObject(object.getContent());
                ConnectorType connectorType = (ConnectorType) prismObject.asObjectable();
                cache.put(connectorType, new CacheValue(connectorType, buildIcfSchema(object), buildConnectorSchema(object)));
            } catch (Exception ex) {
                if (ex instanceof ProcessCanceledException) {
                    throw (ProcessCanceledException) ex;
                }
                LOG.error("Couldn't parse connector object", ex);
            }
        }
        LOG.info("Refresh finished, " + cache.size() + " objects in cache");
    }, AppExecutorUtil.getAppExecutorService());
    LOG.info("Invoke done");
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) MidPointClient(com.evolveum.midpoint.studio.impl.MidPointClient) SearchResult(com.evolveum.midpoint.studio.client.SearchResult) ControlFlowException(com.intellij.openapi.diagnostic.ControlFlowException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 10 with MidPointObject

use of com.evolveum.midpoint.studio.client.MidPointObject in project midpoint-studio by Evolveum.

the class DownloadTask method downloadByOid.

private void downloadByOid() {
    List<VirtualFile> files = new ArrayList<>();
    for (Pair<String, ObjectTypes> pair : oids) {
        try {
            LOG.debug("Downloading " + pair);
            MidPointObject obj = client.get(pair.getSecond().getClassDefinition(), pair.getFirst(), new SearchOptions().raw(raw));
            if (obj == null) {
                continue;
            }
            LOG.debug("Storing file");
            RunnableUtils.runWriteActionAndWait(() -> {
                VirtualFile file = saveFile(obj);
                if (file != null) {
                    files.add(file);
                }
            });
            LOG.debug("File saved");
        } catch (Exception ex) {
            MidPointUtils.publishExceptionNotification(getProject(), getEnvironment(), DownloadTask.class, NOTIFICATION_KEY, "Exception occurred when getting object " + pair.getFirst() + " (" + pair.getSecond().getTypeQName().getLocalPart() + ")", ex);
        }
    }
    if (!files.isEmpty() && openAfterDownload) {
        ApplicationManager.getApplication().invokeAndWait(() -> MidPointUtils.openFile(getProject(), files.get(0)));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MidPointObject(com.evolveum.midpoint.studio.client.MidPointObject) ArrayList(java.util.ArrayList) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) SearchOptions(com.evolveum.midpoint.studio.impl.SearchOptions) IOException(java.io.IOException)

Aggregations

MidPointObject (com.evolveum.midpoint.studio.client.MidPointObject)16 IOException (java.io.IOException)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ArrayList (java.util.ArrayList)6 Environment (com.evolveum.midpoint.studio.impl.Environment)5 MidPointClient (com.evolveum.midpoint.studio.impl.MidPointClient)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 SearchResult (com.evolveum.midpoint.studio.client.SearchResult)4 ProcessObjectResult (com.evolveum.midpoint.studio.action.transfer.ProcessObjectResult)3 SearchOptions (com.evolveum.midpoint.studio.impl.SearchOptions)3 MidPointUtils (com.evolveum.midpoint.studio.util.MidPointUtils)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)3 NotificationType (com.intellij.notification.NotificationType)3 ControlFlowException (com.intellij.openapi.diagnostic.ControlFlowException)3 Logger (com.intellij.openapi.diagnostic.Logger)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Project (com.intellij.openapi.project.Project)3 Writer (java.io.Writer)3 List (java.util.List)3