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);
}
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);
}
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);
}
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");
}
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)));
}
}
Aggregations