Search in sources :

Example 1 with com.evolveum.midpoint.xml.ns._public.resource.capabilities_3

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3 in project midpoint by Evolveum.

the class ExportAction method executeSearch.

private void executeSearch(ModelPortType port, Writer writer) throws FaultMessage, IOException, JAXBException, SAXException {
    SelectorQualifiedGetOptionsType options = createOptions();
    QName type = ObjectType.getType(getParams().getType());
    if (type == null) {
        type = ObjectType.OBJECT.getType();
    }
    int count = 0;
    int currentSize = 1;
    Holder<ObjectListType> list = new Holder<>();
    Holder<OperationResultType> result = new Holder<>();
    while (currentSize > 0) {
        QueryType query = createQuery(count);
        port.searchObjects(type, query, options, list, result);
        OperationResultType res = result.value;
        if (!OperationResultStatusType.SUCCESS.equals(res.getStatus()) && !getParams().isIgnore()) {
            printInfoMessage("Search returned {}, reason: ", res.getStatus(), res.getMessage());
            if (getParams().isVerbose()) {
                printInfoMessage("Operation result:\n{}", ToolsUtils.serializeObject(res));
            }
            break;
        }
        ObjectListType objList = list.value;
        if (getParams().isVerbose()) {
            printInfoMessage("Search returned {}, status: {}/{}", res.getStatus(), count, objList.getCount());
        }
        List<com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType> objects = objList.getObject();
        currentSize = objects.size();
        for (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType object : objects) {
            ToolsUtils.serializeObject(object, writer);
            writer.write('\n');
        }
        count += currentSize;
    }
}
Also used : QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) ObjectType(com.evolveum.midpoint.cli.ninja.util.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 2 with com.evolveum.midpoint.xml.ns._public.resource.capabilities_3

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3 in project midpoint by Evolveum.

the class ExportAction method executeGet.

private void executeGet(ModelPortType port, Writer writer) throws FaultMessage, IOException, JAXBException {
    SelectorQualifiedGetOptionsType options = createOptions();
    QName type = ObjectType.getType(getParams().getType());
    if (type == null) {
        type = ObjectType.OBJECT.getType();
    }
    Holder<com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType> object = new Holder<>();
    Holder<OperationResultType> result = new Holder<>();
    port.getObject(type, getParams().getOid(), options, object, result);
    ToolsUtils.serializeObject(object.value, writer);
}
Also used : ObjectType(com.evolveum.midpoint.cli.ninja.util.ObjectType) QName(javax.xml.namespace.QName) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 3 with com.evolveum.midpoint.xml.ns._public.resource.capabilities_3

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3 in project midpoint by Evolveum.

the class ImportAction method executeAction.

@Override
protected void executeAction() {
    ModelPortType port = createModelPort();
    ModelExecuteOptionsType options = new ModelExecuteOptionsType();
    options.setRaw(getParams().isRaw());
    com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType object = readObject();
    ObjectDeltaType delta = createAddDelta(object);
    ObjectDeltaListType deltas = createDeltaList(delta);
    OperationResultType resultType;
    try {
        ObjectDeltaOperationListType result = port.executeChanges(deltas, options);
        List<ObjectDeltaOperationType> operations = result.getDeltaOperation();
        ObjectDeltaOperationType operation = operations.get(0);
        resultType = operation.getExecutionResult();
    } catch (FaultMessage ex) {
        //todo error handling
        FaultType fault = ex.getFaultInfo();
        resultType = fault.getOperationResult();
    }
    STD_OUT.info("Status: {}", resultType.getStatus());
}
Also used : ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) ModelExecuteOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType) FaultType(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultType) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)

Example 4 with com.evolveum.midpoint.xml.ns._public.resource.capabilities_3

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3 in project midpoint by Evolveum.

the class NotificationsTest method test160LocalizedMessageTemplateAttachmentInheritance.

@Test
public void test160LocalizedMessageTemplateAttachmentInheritance() throws Exception {
    OperationResult result = getTestOperationResult();
    given("localized message template with attachment");
    String objectName = "messageTemplate" + getTestNumber();
    String templateOid = repositoryService.addObject(new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).bodyExpression(velocityExpression("template-body-default")).attachmentExpression(groovyExpression("def a = new com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType();\n" + "a.setContentType(\"text/plain\");\n" + "a.setContent(\"default-content1\");\n" + "return a;")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("default-content2"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("sk").bodyExpression(velocityExpression("template-body-sk")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("sk-content2"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("cz").bodyExpression(velocityExpression("template-body-cz")).attachmentExpression(groovyExpression("def a = new com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType();\n" + "a.setContentType(\"text/plain\");\n" + "a.setContent(\"cz-content1\");\n" + "return a;"))).asPrismObject(), null, result);
    and("configuration with transport and notifier using the template");
    Collection<? extends ItemDelta<?, ?>> modifications = systemConfigModificationWithTestTransport("test").item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().messageTemplateRef(createObjectReference(templateOid, MessageTemplateType.COMPLEX_TYPE, null)).transport("test")))).asItemDeltas();
    repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
    TestMessageTransport testTransport = (TestMessageTransport) transportService.getTransport("test");
    assertThat(testTransport.getMessages()).isEmpty();
    when("event is sent to notification manager, recipient has no language set");
    CustomEventImpl event = createCustomEvent();
    // This is used as default recipient, no recipient results in no message.
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user@example.com")));
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with default template content");
    Message message = getSingleMessage(testTransport);
    assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
    a -> getRawValue(a.getContent()).equals("default-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("default-content2"));
    // now when-then for sk language (attachment expression inherited)
    when("recipient has 'sk' language set");
    event = createCustomEvent();
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user2@example.com").preferredLanguage("sk")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("message uses attachment expression from default content");
    message = getSingleMessage(testTransport);
    assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
    a -> getRawValue(a.getContent()).equals("default-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("sk-content2"));
    // now when-then for cz language (attachment inherited)
    when("event is sent to notification manager, recipient has 'cz' language set");
    event = createCustomEvent();
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user3@example.com").preferredLanguage("cz")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with default template content, because no localized content for specified language is found");
    message = getSingleMessage(testTransport);
    assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
    a -> getRawValue(a.getContent()).equals("cz-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("default-content2"));
}
Also used : CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) SimpleExpressionUtil(com.evolveum.midpoint.schema.util.SimpleExpressionUtil) NotificationManager(com.evolveum.midpoint.notifications.api.NotificationManager) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) CustomMessageTransport(com.evolveum.midpoint.transport.impl.CustomMessageTransport) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MailMessageTransport(com.evolveum.midpoint.transport.impl.MailMessageTransport) FileMessageTransport(com.evolveum.midpoint.transport.impl.FileMessageTransport) LightweightIdentifier(com.evolveum.midpoint.task.api.LightweightIdentifier) TransportService(com.evolveum.midpoint.notifications.api.transports.TransportService) LightweightIdentifierGenerator(com.evolveum.midpoint.task.api.LightweightIdentifierGenerator) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) Message(com.evolveum.midpoint.notifications.api.transports.Message) SmsMessageTransport(com.evolveum.midpoint.transport.impl.SmsMessageTransport) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NotNull(org.jetbrains.annotations.NotNull) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Message(com.evolveum.midpoint.notifications.api.transports.Message) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 5 with com.evolveum.midpoint.xml.ns._public.resource.capabilities_3

use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3 in project midpoint by Evolveum.

the class ParamsTypeUtil method createEntryElement.

/**
	 * Temporary workaround, brutally hacked -- so that the conversion 
	 * of OperationResult into OperationResultType 'somehow' works, at least to the point
	 * where when we:
	 * - have OR1
	 * - serialize it into ORT1
	 * - then deserialize into OR2
	 * - serialize again into ORT2
	 * so we get ORT1.equals(ORT2) - at least in our simple test case :)
	 * 
	 * FIXME: this should be definitely reworked
	 * 
	 * @param entry
	 * @return
	 */
private static EntryType createEntryElement(String key, Serializable value) {
    EntryType entryType = new EntryType();
    entryType.setKey(key);
    if (value != null) {
        Document doc = DOMUtil.getDocument();
        if (value instanceof ObjectType && ((ObjectType) value).getOid() != null) {
            // Store only reference on the OID. This is faster and getObject can be used to retrieve
            // the object if needed. Although is does not provide 100% accuracy, it is a good tradeoff.
            setObjectReferenceEntry(entryType, ((ObjectType) value));
        // these values should be put 'as they are', in order to be deserialized into themselves
        } else if (value instanceof String || value instanceof Integer || value instanceof Long) {
            entryType.setEntryValue(new JAXBElement<Serializable>(SchemaConstants.C_PARAM_VALUE, Serializable.class, value));
        } else if (XmlTypeConverter.canConvert(value.getClass())) {
        //				try {
        //					entryType.setEntryValue(new JXmlTypeConverter.toXsdElement(value, SchemaConstants.C_PARAM_VALUE, doc, true));
        //				} catch (SchemaException e) {
        //					LOGGER.error("Cannot convert value {} to XML: {}",value,e.getMessage());
        //					setUnknownJavaObjectEntry(entryType, value);
        //				}
        } else if (value instanceof Element || value instanceof JAXBElement<?>) {
            entryType.setEntryValue((JAXBElement<?>) value);
        // FIXME: this is really bad code ... it means that 'our' JAXB object should be put as is
        } else if ("com.evolveum.midpoint.xml.ns._public.common.common_3".equals(value.getClass().getPackage().getName())) {
            JAXBElement<Object> o = new JAXBElement<Object>(SchemaConstants.C_PARAM_VALUE, Object.class, value);
            entryType.setEntryValue(o);
        } else {
            setUnknownJavaObjectEntry(entryType, value);
        }
    }
    return entryType;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) UnknownJavaObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.UnknownJavaObjectType) EntryType(com.evolveum.midpoint.xml.ns._public.common.common_3.EntryType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement) Document(org.w3c.dom.Document)

Aggregations

OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)3 ObjectType (com.evolveum.midpoint.cli.ninja.util.ObjectType)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)2 QName (javax.xml.namespace.QName)2 Holder (javax.xml.ws.Holder)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 NotificationManager (com.evolveum.midpoint.notifications.api.NotificationManager)1 Message (com.evolveum.midpoint.notifications.api.transports.Message)1 TransportService (com.evolveum.midpoint.notifications.api.transports.TransportService)1 CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SimpleExpressionUtil (com.evolveum.midpoint.schema.util.SimpleExpressionUtil)1 LightweightIdentifier (com.evolveum.midpoint.task.api.LightweightIdentifier)1 LightweightIdentifierGenerator (com.evolveum.midpoint.task.api.LightweightIdentifierGenerator)1 Task (com.evolveum.midpoint.task.api.Task)1