Search in sources :

Example 76 with PolyStringType

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());
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test)

Example 77 with PolyStringType

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);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Example 78 with PolyStringType

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);
        }
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType)

Example 79 with PolyStringType

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
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) Scene(com.evolveum.midpoint.model.api.visualizer.Scene) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 80 with PolyStringType

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;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)

Aggregations

PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)94 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 Test (org.testng.annotations.Test)23 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)20 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 QName (javax.xml.namespace.QName)11 Task (com.evolveum.midpoint.task.api.Task)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 File (java.io.File)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ArrayList (java.util.ArrayList)7 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4