use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class TestParseDiffPatch method testUser.
@Test
public void testUser() throws SchemaException, SAXException, IOException, JAXBException {
System.out.println("===[ testUser ]===");
PrismObject<UserType> userBefore = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-before.xml"));
userBefore.checkConsistence();
PrismObject<UserType> userAfter = PrismTestUtil.parseObject(new File(TEST_DIR, "user-jack-after.xml"));
userAfter.checkConsistence();
// sanity
assertFalse("Equals does not work", userBefore.equals(userAfter));
// WHEN
ObjectDelta<UserType> userDelta = userBefore.diff(userAfter);
// THEN
System.out.println("DELTA:");
System.out.println(userDelta.debugDump());
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
userDelta.assertDefinitions();
assertEquals("Wrong delta OID", userBefore.getOid(), userDelta.getOid());
assertEquals("Wrong change type", ChangeType.MODIFY, userDelta.getChangeType());
Collection<? extends ItemDelta> modifications = userDelta.getModifications();
assertEquals("Unexpected number of modifications", 3, modifications.size());
PrismAsserts.assertPropertyReplace(userDelta, new QName(SchemaConstants.NS_C, "fullName"), new PolyString("Cpt. Jack Sparrow", "cpt jack sparrow"));
PrismAsserts.assertPropertyAdd(userDelta, new QName(SchemaConstants.NS_C, "honorificPrefix"), new PolyString("Cpt.", "cpt"));
PrismAsserts.assertPropertyAdd(userDelta, new QName(SchemaConstants.NS_C, "locality"), new PolyString("Tortuga", "tortuga"));
ObjectModificationType objectModificationType = DeltaConvertor.toObjectModificationType(userDelta);
System.out.println("Modification XML:");
System.out.println(PrismTestUtil.serializeAnyDataWrapped(objectModificationType));
assertEquals("Wrong delta OID", userBefore.getOid(), objectModificationType.getOid());
List<ItemDeltaType> propertyModifications = objectModificationType.getItemDelta();
assertEquals("Unexpected number of modifications", 3, propertyModifications.size());
PolyStringType polyString = new PolyStringType();
polyString.setOrig("Cpt. Jack Sparrow");
polyString.setNorm("cpt jack sparrow");
assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "fullName"), ModificationTypeType.REPLACE, polyString);
polyString = new PolyStringType();
polyString.setOrig("Cpt.");
polyString.setNorm("cpt");
assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "honorificPrefix"), ModificationTypeType.ADD, polyString);
polyString = new PolyStringType();
polyString.setOrig("Tortuga");
polyString.setNorm("tortuga");
assertXmlPolyMod(objectModificationType, new QName(SchemaConstants.NS_C, "locality"), ModificationTypeType.ADD, polyString);
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
// ROUNDTRIP
userDelta.applyTo(userBefore);
userBefore.checkConsistence();
userAfter.checkConsistence();
userDelta.checkConsistence();
//assertEquals("Round trip failed", userAfter, userBefore);
assertTrue("Not equivalent", userBefore.equivalent(userAfter));
ObjectDelta<UserType> roundTripDelta = DiffUtil.diff(userBefore, userAfter);
System.out.println("roundtrip DELTA:");
System.out.println(roundTripDelta.debugDump());
assertTrue("Roundtrip delta is not empty", roundTripDelta.isEmpty());
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class TestParseDiffPatch method assertModificationPolyStringValue.
private void assertModificationPolyStringValue(RawType value, PolyStringType... expectedValues) throws SchemaException {
XNode xnode = value.serializeToXNode();
assertFalse(xnode.isEmpty());
PolyStringType valueAsPoly = value.getPrismContext().parserFor(new RootXNode(new QName("dummy"), xnode)).parseRealValue(PolyStringType.class);
boolean found = false;
for (PolyStringType expectedValue : expectedValues) {
if (expectedValue.getOrig().equals(valueAsPoly.getOrig()) && expectedValue.getNorm().equals(valueAsPoly.getNorm())) {
found = true;
}
}
assertTrue(found);
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class LensUtil method checkContextSanity.
public static <F extends ObjectType> void checkContextSanity(LensContext<F> context, String activityDescription, OperationResult result) throws SchemaException, PolicyViolationException {
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
PrismObject<F> focusObjectNew = focusContext.getObjectNew();
if (focusObjectNew != null) {
PolyStringType namePolyType = focusObjectNew.asObjectable().getName();
if (namePolyType == null) {
throw new SchemaException("Focus " + focusObjectNew + " does not have a name after " + activityDescription);
}
ObjectPolicyConfigurationType objectPolicyConfigurationType = focusContext.getObjectPolicyConfigurationType();
checkObjectPolicy(focusContext, objectPolicyConfigurationType);
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class TestVisualizer method test100UserBasic.
@Test
public void test100UserBasic() throws Exception {
final String TEST_NAME = "test100UserBasic";
Task task = createTask(TEST_NAME);
PrismObject<UserType> u = prismContext.createObject(UserType.class);
u.setOid("123");
u.asObjectable().setName(new PolyStringType("user123"));
u.asObjectable().setFullName(new PolyStringType("User User123"));
/// WHEN
displayWhen(TEST_NAME);
final Scene scene = visualizer.visualize(u, task, task.getResult());
// THEN
displayThen(TEST_NAME);
display("scene", scene);
// TODO some asserts
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class ShadowCache method completeShadow.
/**
* Make sure that the shadow is complete, e.g. that all the mandatory fields
* are filled (e.g name, resourceRef, ...) Also transforms the shadow with
* respect to simulated capabilities.
*/
private PrismObject<ShadowType> completeShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, PrismObject<ShadowType> repoShadow, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, GenericConnectorException, ExpressionEvaluationException {
PrismObject<ShadowType> resultShadow = repoShadow.clone();
// The real definition may be different than that of repo shadow (e.g.
// different auxiliary object classes).
resultShadow.applyDefinition(ctx.getObjectClassDefinition().getObjectDefinition(), true);
assert resultShadow.getPrismContext() != null : "No prism context in resultShadow";
ResourceAttributeContainer resourceAttributesContainer = ShadowUtil.getAttributesContainer(resourceShadow);
ShadowType resultShadowType = resultShadow.asObjectable();
ShadowType repoShadowType = repoShadow.asObjectable();
ShadowType resourceShadowType = resourceShadow.asObjectable();
Collection<QName> auxObjectClassQNames = new ArrayList<>();
// Always take auxiliary object classes from the resource. Unlike
// structural object classes
// the auxiliary object classes may change.
resultShadow.removeProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS);
PrismProperty<QName> resourceAuxOcProp = resourceShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS);
if (resourceAuxOcProp != null) {
PrismProperty<QName> resultAuxOcProp = resultShadow.findOrCreateProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS);
resultAuxOcProp.addAll(PrismPropertyValue.cloneCollection(resourceAuxOcProp.getValues()));
auxObjectClassQNames.addAll(resultAuxOcProp.getRealValues());
}
resultShadowType.setName(new PolyStringType(ShadowUtil.determineShadowName(resourceShadow)));
if (resultShadowType.getObjectClass() == null) {
resultShadowType.setObjectClass(resourceAttributesContainer.getDefinition().getTypeName());
}
if (resultShadowType.getResource() == null) {
resultShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource()));
}
// Attributes
resultShadow.removeContainer(ShadowType.F_ATTRIBUTES);
ResourceAttributeContainer resultAttibutes = resourceAttributesContainer.clone();
accessChecker.filterGetAttributes(resultAttibutes, ctx.computeCompositeObjectClassDefinition(auxObjectClassQNames), parentResult);
resultShadow.add(resultAttibutes);
resultShadowType.setIgnored(resourceShadowType.isIgnored());
resultShadowType.setActivation(resourceShadowType.getActivation());
ShadowType resultAccountShadow = resultShadow.asObjectable();
ShadowType resourceAccountShadow = resourceShadow.asObjectable();
// Credentials
resultAccountShadow.setCredentials(resourceAccountShadow.getCredentials());
transplantPasswordMetadata(repoShadowType, resultAccountShadow);
// protected
ProvisioningUtil.setProtectedFlag(ctx, resultShadow, matchingRuleRegistry);
// exists, dead
resultShadowType.setExists(resourceShadowType.isExists());
// Activation
ActivationType resultActivationType = resultShadowType.getActivation();
ActivationType repoActivation = repoShadowType.getActivation();
if (repoActivation != null) {
if (resultActivationType == null) {
resultActivationType = new ActivationType();
resultShadowType.setActivation(resultActivationType);
}
resultActivationType.setId(repoActivation.getId());
// .. but we want metadata from repo
resultActivationType.setDisableReason(repoActivation.getDisableReason());
resultActivationType.setEnableTimestamp(repoActivation.getEnableTimestamp());
resultActivationType.setDisableTimestamp(repoActivation.getDisableTimestamp());
resultActivationType.setArchiveTimestamp(repoActivation.getArchiveTimestamp());
resultActivationType.setValidityChangeTimestamp(repoActivation.getValidityChangeTimestamp());
}
// Associations
PrismContainer<ShadowAssociationType> resourceAssociationContainer = resourceShadow.findContainer(ShadowType.F_ASSOCIATION);
if (resourceAssociationContainer != null) {
PrismContainer<ShadowAssociationType> associationContainer = resourceAssociationContainer.clone();
resultShadow.addReplaceExisting(associationContainer);
if (associationContainer != null) {
for (PrismContainerValue<ShadowAssociationType> associationCVal : associationContainer.getValues()) {
ResourceAttributeContainer identifierContainer = ShadowUtil.getAttributesContainer(associationCVal, ShadowAssociationType.F_IDENTIFIERS);
Collection<ResourceAttribute<?>> entitlementIdentifiers = identifierContainer.getAttributes();
if (entitlementIdentifiers == null || entitlementIdentifiers.isEmpty()) {
throw new IllegalStateException("No entitlement identifiers present for association " + associationCVal + " " + ctx.getDesc());
}
ShadowAssociationType shadowAssociationType = associationCVal.asContainerable();
QName associationName = shadowAssociationType.getName();
RefinedAssociationDefinition rEntitlementAssociation = ctx.getObjectClassDefinition().findAssociationDefinition(associationName);
if (rEntitlementAssociation == null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Entitlement association with name {} couldn't be found in {} {}\nresource shadow:\n{}\nrepo shadow:\n{}", new Object[] { associationName, ctx.getObjectClassDefinition(), ctx.getDesc(), resourceShadow.debugDump(1), repoShadow == null ? null : repoShadow.debugDump(1) });
LOGGER.trace("Full refined definition: {}", ctx.getObjectClassDefinition().debugDump());
}
throw new SchemaException("Entitlement association with name " + associationName + " couldn't be found in " + ctx.getObjectClassDefinition() + " " + ctx.getDesc() + ", with using shadow coordinates " + ctx.isUseRefinedDefinition());
}
ShadowKindType entitlementKind = rEntitlementAssociation.getKind();
if (entitlementKind == null) {
entitlementKind = ShadowKindType.ENTITLEMENT;
}
for (String entitlementIntent : rEntitlementAssociation.getIntents()) {
ProvisioningContext ctxEntitlement = ctx.spawn(entitlementKind, entitlementIntent);
PrismObject<ShadowType> entitlementRepoShadow;
PrismObject<ShadowType> entitlementShadow = (PrismObject<ShadowType>) identifierContainer.getUserData(ResourceObjectConverter.FULL_SHADOW_KEY);
if (entitlementShadow == null) {
try {
entitlementRepoShadow = shadowManager.lookupShadowInRepository(ctxEntitlement, identifierContainer, parentResult);
if (entitlementRepoShadow == null) {
entitlementShadow = resouceObjectConverter.locateResourceObject(ctxEntitlement, entitlementIdentifiers, parentResult);
// Try to look up repo shadow again, this
// time with full resource shadow. When we
// have searched before we might
// have only some identifiers. The shadow
// might still be there, but it may be
// renamed
entitlementRepoShadow = shadowManager.lookupShadowInRepository(ctxEntitlement, entitlementShadow, parentResult);
if (entitlementRepoShadow == null) {
entitlementRepoShadow = createShadowInRepository(ctxEntitlement, entitlementShadow, false, parentResult);
}
}
} catch (ObjectNotFoundException e) {
// The entitlement to which we point is not
// there.
// Simply ignore this association value.
parentResult.muteLastSubresultError();
LOGGER.warn("The entitlement identified by {} referenced from {} does not exist. Skipping.", new Object[] { associationCVal, resourceShadow });
continue;
} catch (SchemaException e) {
// The entitlement to which we point is not bad.
// Simply ignore this association value.
parentResult.muteLastSubresultError();
LOGGER.warn("The entitlement identified by {} referenced from {} violates the schema. Skipping. Original error: {}", new Object[] { associationCVal, resourceShadow, e.getMessage(), e });
continue;
}
} else {
entitlementRepoShadow = lookupOrCreateShadowInRepository(ctxEntitlement, entitlementShadow, false, parentResult);
}
ObjectReferenceType shadowRefType = new ObjectReferenceType();
shadowRefType.setOid(entitlementRepoShadow.getOid());
shadowRefType.setType(ShadowType.COMPLEX_TYPE);
shadowAssociationType.setShadowRef(shadowRefType);
}
}
}
}
resultShadowType.setCachingMetadata(resourceShadowType.getCachingMetadata());
// Sanity asserts to catch some exotic bugs
PolyStringType resultName = resultShadow.asObjectable().getName();
assert resultName != null : "No name generated in " + resultShadow;
assert !StringUtils.isEmpty(resultName.getOrig()) : "No name (orig) in " + resultShadow;
assert !StringUtils.isEmpty(resultName.getNorm()) : "No name (norm) in " + resultShadow;
return resultShadow;
}
Aggregations