Search in sources :

Example 1 with ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType 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 ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType 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 ObjectType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType 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 ObjectType

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

the class ToolsUtils method serializeObject.

public static void serializeObject(Object object, Writer writer) throws JAXBException {
    if (object == null) {
        return;
    }
    Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    if (object instanceof ObjectType) {
        object = new JAXBElement(C_OBJECT, Object.class, object);
    }
    marshaller.marshal(object, writer);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Marshaller(javax.xml.bind.Marshaller) JAXBElement(javax.xml.bind.JAXBElement)

Example 5 with ObjectType

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

the class PageAdminObjectDetails method saveOrPreviewPerformed.

public void saveOrPreviewPerformed(AjaxRequestTarget target, OperationResult result, boolean previewOnly) {
    boolean isAnythingChanged = processDeputyAssignments();
    ObjectWrapper<O> objectWrapper = getObjectWrapper();
    LOGGER.debug("Saving object {}", objectWrapper);
    // todo: improve, delta variable is quickfix for MID-1006
    // redirecting to user list page everytime user is created in repository
    // during user add in gui,
    // and we're not taking care about account/assignment create errors
    // (error message is still displayed)
    delta = null;
    Task task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
    ModelExecuteOptions options = getExecuteChangesOptions();
    LOGGER.debug("Using execute options {}.", new Object[] { options });
    try {
        reviveModels();
        delta = objectWrapper.getObjectDelta();
        if (objectWrapper.getOldDelta() != null) {
            delta = ObjectDelta.summarize(objectWrapper.getOldDelta(), delta);
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("User delta computed from form:\n{}", new Object[] { delta.debugDump(3) });
        }
    } catch (Exception ex) {
        result.recordFatalError(getString("pageUser.message.cantCreateUser"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
        showResult(result);
        return;
    }
    switch(objectWrapper.getStatus()) {
        case ADDING:
            try {
                PrismObject<O> objectToAdd = delta.getObjectToAdd();
                WebComponentUtil.encryptCredentials(objectToAdd, true, getMidpointApplication());
                prepareObjectForAdd(objectToAdd);
                getPrismContext().adopt(objectToAdd, getCompileTimeClass());
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before add user:\n{}", new Object[] { delta.debugDump(3) });
                }
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                    final Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
                    final Collection<SimpleValidationError> validationErrors = performCustomValidation(objectToAdd, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
                } else {
                    result.recordSuccess();
                }
            } catch (Exception ex) {
                result.recordFatalError(getString("pageFocus.message.cantCreateFocus"), ex);
                LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
                showResult(result);
            }
            break;
        case MODIFYING:
            try {
                WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
                prepareObjectDeltaForModify(delta);
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before modify user:\n{}", new Object[] { delta.debugDump(3) });
                }
                Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                    deltas.add(delta);
                }
                List<ObjectDelta<? extends ObjectType>> additionalDeltas = getAdditionalModifyDeltas(result);
                if (additionalDeltas != null) {
                    for (ObjectDelta additionalDelta : additionalDeltas) {
                        if (!additionalDelta.isEmpty()) {
                            additionalDelta.revive(getPrismContext());
                            deltas.add(additionalDelta);
                        }
                    }
                }
                if (delta.isEmpty() && ModelExecuteOptions.isReconcile(options)) {
                    ObjectDelta emptyDelta = ObjectDelta.createEmptyModifyDelta(getCompileTimeClass(), objectWrapper.getObject().getOid(), getPrismContext());
                    deltas.add(emptyDelta);
                    Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
                } else if (!deltas.isEmpty()) {
                    Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
                } else {
                    // from previous attempts (useful only if we would call finishProcessing at the end, but that's not the case now)
                    progressReporter.clearProgressPanel();
                    if (!previewOnly) {
                        if (!isAnythingChanged) {
                            result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
                            showResult(result);
                        }
                        redirectBack();
                    } else {
                        warn(getString("PageAdminObjectDetails.noChangesPreview"));
                        target.add(getFeedbackPanel());
                    }
                }
            } catch (Exception ex) {
                if (!executeForceDelete(objectWrapper, task, options, result)) {
                    result.recordFatalError(getString("pageUser.message.cantUpdateUser"), ex);
                    LoggingUtils.logUnexpectedException(LOGGER, getString("pageUser.message.cantUpdateUser"), ex);
                } else {
                    result.recomputeStatus();
                }
                showResult(result);
            }
            break;
        // support for add/delete containers (e.g. delete credentials)
        default:
            error(getString("pageAdminFocus.message.unsupportedState", objectWrapper.getStatus()));
    }
    //		result.recomputeStatus();
    //
    //		if (!result.isInProgress()) {
    //			LOGGER.trace("Result NOT in progress, calling finishProcessing");
    //			finishProcessing(target, result, false);
    //		}
    LOGGER.trace("returning from saveOrPreviewPerformed");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SimpleValidationError(com.evolveum.midpoint.web.util.validation.SimpleValidationError)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)243 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)185 Task (com.evolveum.midpoint.task.api.Task)106 Test (org.testng.annotations.Test)106 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)96 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)86 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)83 ArrayList (java.util.ArrayList)74 QName (javax.xml.namespace.QName)71 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)62 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)57 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)57 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)56 Holder (javax.xml.ws.Holder)51 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)45 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)43 PrismObject (com.evolveum.midpoint.prism.PrismObject)39 NotNull (org.jetbrains.annotations.NotNull)36 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)33 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)31