Search in sources :

Example 21 with PrismObject

use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.

the class PageReport method createFullXmlValidator.

private IValidator<String> createFullXmlValidator() {
    return new IValidator<String>() {

        @Override
        public void validate(IValidatable<String> validatable) {
            String value = validatable.getValue();
            OperationResult result = new OperationResult(OPERATION_VALIDATE_REPORT);
            Holder<PrismObject<ReportType>> reportHolder = new Holder<>(null);
            OpResult opResult = null;
            try {
                validateObject(value, reportHolder, PrismContext.LANG_XML, true, result);
                if (!result.isAcceptable()) {
                    result.recordFatalError("Could not validate object", result.getCause());
                    opResult = OpResult.getOpResult((PageBase) getPage(), result);
                    validatable.error(new RawValidationError(opResult));
                }
            } catch (Exception e) {
                LOGGER.error("Validation problem occured." + e.getMessage());
                result.recordFatalError("Could not validate object.", e);
                try {
                    opResult = OpResult.getOpResult((PageBase) getPage(), result);
                    validatable.error(new RawValidationError(opResult));
                } catch (Exception ex) {
                    error(ex);
                }
            }
        }
    };
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) IValidator(org.apache.wicket.validation.IValidator) Holder(com.evolveum.midpoint.util.Holder) OpResult(com.evolveum.midpoint.gui.api.component.result.OpResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) RawValidationError(org.apache.wicket.validation.RawValidationError) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IValidatable(org.apache.wicket.validation.IValidatable)

Example 22 with PrismObject

use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.

the class PageReport method createFullXmlModel.

private IModel<String> createFullXmlModel() {
    return new IModel<String>() {

        @Override
        public String getObject() {
            PrismObject report = model.getObject().getObject();
            if (report == null) {
                return null;
            }
            try {
                return getPrismContext().serializeObjectToString(report, PrismContext.LANG_XML);
            } catch (SchemaException ex) {
                getSession().error(getString("PageReport.message.cantSerializeFromObjectToString") + ex);
                throw new RestartResponseException(PageError.class);
            }
        }

        @Override
        public void setObject(String object) {
            OperationResult result = new OperationResult(OPERATION_VALIDATE_REPORT);
            Holder<PrismObject<ReportType>> reportHolder = new Holder<>(null);
            try {
                validateObject(object, reportHolder, PrismContext.LANG_XML, true, result);
                model.getObject().setObject(reportHolder.getValue());
            } catch (Exception e) {
                LOGGER.error("Could not set object. Validation problem occured." + result.getMessage());
                result.recordFatalError("Could not set object. Validation problem occured,", e);
                showResult(result, "Could not set object. Validation problem occured.");
            }
        }

        @Override
        public void detach() {
        }
    };
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IModel(org.apache.wicket.model.IModel) RestartResponseException(org.apache.wicket.RestartResponseException) Holder(com.evolveum.midpoint.util.Holder) PageError(com.evolveum.midpoint.web.page.error.PageError) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 23 with PrismObject

use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.

the class RefinedConnectorSchemaImpl method getConnectorSchema.

public static ConnectorSchema getConnectorSchema(PrismObject<ConnectorType> connector, PrismContext prismContext) throws SchemaException {
    Element connectorXsdSchema = ConnectorTypeUtil.getConnectorXsdSchema(connector);
    if (connectorXsdSchema == null) {
        return null;
    }
    Object userDataEntry = connector.getUserData(USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA);
    if (userDataEntry != null) {
        if (userDataEntry instanceof ConnectorSchema) {
            return (ConnectorSchema) userDataEntry;
        } else {
            throw new IllegalStateException("Expected ConnectorSchema under user data key " + USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA + "in " + connector + ", but got " + userDataEntry.getClass());
        }
    } else {
        //InternalMonitor.recordConnectorSchemaParse();
        ConnectorSchemaImpl parsedSchema = ConnectorSchemaImpl.parse(connectorXsdSchema, "connector schema of " + connector, prismContext);
        if (parsedSchema == null) {
            throw new IllegalStateException("Parsed schema is null: most likely an internall error");
        }
        parsedSchema.setUsualNamespacePrefix(ConnectorSchemaImpl.retrieveUsualNamespacePrefix(connector.asObjectable()));
        connector.setUserData(USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA, parsedSchema);
        return parsedSchema;
    }
}
Also used : ConnectorSchema(com.evolveum.midpoint.schema.processor.ConnectorSchema) Element(org.w3c.dom.Element) ConnectorSchemaImpl(com.evolveum.midpoint.schema.processor.ConnectorSchemaImpl) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 24 with PrismObject

use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.

the class TestJaxbSanity method testUnmarshallAndEqualsResource.

@Test
public void testUnmarshallAndEqualsResource() throws JAXBException, SchemaException, FileNotFoundException {
    System.out.println("\n\n ===[testUnmarshallAndEqualsResource]===\n");
    // GIVEN
    ResourceType resource1Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
    assertNotNull(resource1Type);
    System.out.println("Resource1 " + resource1Type.asPrismObject().debugDump());
    PrismObject resource1 = resource1Type.asPrismObject();
    ResourceType resource2Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
    assertNotNull(resource2Type);
    System.out.println("Resource2 " + resource2Type.asPrismObject().debugDump());
    PrismObject resource2 = resource2Type.asPrismObject();
    // WHEN, THEN
    ObjectDelta<ResourceType> objectDelta = resource1.diff(resource2);
    System.out.println("Resource delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Resource delta is not empty", objectDelta.isEmpty());
    assertTrue("Resource not equal", resource1Type.equals(resource2Type));
    System.out.println("HASH");
    System.out.println(resource1Type.hashCode());
    System.out.println(resource2Type.hashCode());
    assertTrue("Resource hashcode does not match", resource1Type.hashCode() == resource2Type.hashCode());
    PrismPropertyValue<Object> pv1 = new PrismPropertyValue<Object>(resource1Type.getConnectorConfiguration());
    PrismPropertyValue<Object> pv2 = new PrismPropertyValue<Object>(resource2Type.getConnectorConfiguration());
    assertTrue("Real property values not equal", pv1.equalsRealValue(pv2));
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) File(java.io.File) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 25 with PrismObject

use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.

the class TestMappingDynamicSysVar method testEmployeeTypeDeltaBreplaceB.

@Test
public void testEmployeeTypeDeltaBreplaceB() throws Exception {
    final String TEST_NAME = "testEmployeeTypeDeltaBreplaceB";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_EMPLOYEE_TYPE, evaluator.getPrismContext(), "B");
    Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>> mapping = evaluator.createMapping("mapping-script-system-variables-employee-type.xml", TEST_NAME, "employeeType", delta);
    PrismObject<UserType> user = (PrismObject<UserType>) mapping.getSourceContext().getOldObject();
    setEmployeeType(user.asObjectable(), "B");
    mapping.getSourceContext().recompute();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    evaluator.assertResult(opResult);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = mapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, "B");
    PrismAsserts.assertTripleNoMinus(outputTriple);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)696 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)484 Test (org.testng.annotations.Test)317 Task (com.evolveum.midpoint.task.api.Task)307 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)288 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)147 ArrayList (java.util.ArrayList)113 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)92 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)72 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)72 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)68 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)61 List (java.util.List)61 QName (javax.xml.namespace.QName)60 SystemException (com.evolveum.midpoint.util.exception.SystemException)46 File (java.io.File)46 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)44 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)42 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38