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