Search in sources :

Example 96 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class RAnyConverter method convertToRValue.

//todo assignment parameter really messed up this method, proper interfaces must be introduced later [lazyman]
public Set<RAnyValue> convertToRValue(Item item, boolean assignment) throws DtoTranslationException {
    Validate.notNull(item, "Object for converting must not be null.");
    Validate.notNull(item.getDefinition(), "Item '" + item.getElementName() + "' without definition can't be saved.");
    ItemDefinition definition = item.getDefinition();
    Set<RAnyValue> rValues = new HashSet<>();
    if (!isIndexed(definition, prismContext)) {
        return rValues;
    }
    try {
        RAnyValue rValue;
        List<PrismValue> values = item.getValues();
        for (PrismValue value : values) {
            if (value instanceof PrismPropertyValue) {
                PrismPropertyValue propertyValue = (PrismPropertyValue) value;
                //todo  omg, do something with this!!! [lazyman]
                switch(getValueType(definition.getTypeName())) {
                    case BOOLEAN:
                        {
                            Boolean repoValue = extractValue(propertyValue, Boolean.class);
                            if (assignment) {
                                rValue = new RAExtBoolean(repoValue);
                            } else {
                                rValue = new ROExtBoolean(repoValue);
                            }
                            break;
                        }
                    case LONG:
                        {
                            Long repoValue = extractValue(propertyValue, Long.class);
                            if (assignment) {
                                rValue = new RAExtLong(repoValue);
                            } else {
                                rValue = new ROExtLong(repoValue);
                            }
                            break;
                        }
                    case DATE:
                        {
                            Timestamp repoValue = extractValue(propertyValue, Timestamp.class);
                            if (assignment) {
                                rValue = new RAExtDate(repoValue);
                            } else {
                                rValue = new ROExtDate(repoValue);
                            }
                            break;
                        }
                    case POLY_STRING:
                        {
                            PolyString repoValue = extractValue(propertyValue, PolyString.class);
                            if (assignment) {
                                rValue = new RAExtPolyString(repoValue);
                            } else {
                                rValue = new ROExtPolyString(repoValue);
                            }
                            break;
                        }
                    case STRING:
                    default:
                        {
                            String repoValue = extractValue(propertyValue, String.class);
                            if (assignment) {
                                rValue = new RAExtString(repoValue);
                            } else {
                                rValue = new ROExtString(repoValue);
                            }
                        }
                }
            } else if (value instanceof PrismReferenceValue) {
                if (assignment) {
                    PrismReferenceValue referenceValue = (PrismReferenceValue) value;
                    rValue = RAExtReference.createReference(referenceValue);
                } else {
                    PrismReferenceValue referenceValue = (PrismReferenceValue) value;
                    rValue = ROExtReference.createReference(referenceValue);
                }
            } else if (value == null) {
                // shouldn't occur anyway
                continue;
            } else {
                // shouldn't get here because if isIndexed test above
                throw new AssertionError("Wrong value type: " + value);
            }
            rValue.setName(RUtil.qnameToString(definition.getName()));
            rValue.setType(RUtil.qnameToString(definition.getTypeName()));
            rValue.setValueType(getValueType(value.getParent()));
            rValue.setDynamic(definition.isDynamic());
            rValues.add(rValue);
        }
    } catch (Exception ex) {
        throw new DtoTranslationException("Exception when translating " + item + ": " + ex.getMessage(), ex);
    }
    return rValues;
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Timestamp(java.sql.Timestamp) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 97 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class AuditServiceProxy method completeRecord.

/**
	 * Complete the record with data that can be computed or discovered from the
	 * environment
	 */
private void completeRecord(AuditEventRecord record, Task task) {
    LightweightIdentifier id = null;
    if (record.getEventIdentifier() == null) {
        id = lightweightIdentifierGenerator.generate();
        record.setEventIdentifier(id.toString());
    }
    if (record.getTimestamp() == null) {
        if (id == null) {
            record.setTimestamp(System.currentTimeMillis());
        } else {
            // To be consistent with the ID
            record.setTimestamp(id.getTimestamp());
        }
    }
    if (record.getTaskIdentifier() == null && task != null) {
        record.setTaskIdentifier(task.getTaskIdentifier());
    }
    if (record.getTaskOID() == null && task != null) {
        record.setTaskOID(task.getOid());
    }
    if (record.getChannel() == null && task != null) {
        record.setChannel(task.getChannel());
    }
    if (record.getInitiator() == null && task != null) {
        record.setInitiator(task.getOwner());
    }
    if (record.getNodeIdentifier() == null && taskManager != null) {
        record.setNodeIdentifier(taskManager.getNodeId());
    }
    HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    if (connInfo == null && securityEnforcer != null) {
        connInfo = securityEnforcer.getStoredConnectionInformation();
    }
    if (connInfo != null) {
        if (record.getSessionIdentifier() == null) {
            record.setSessionIdentifier(connInfo.getSessionId());
        }
        if (record.getRemoteHostAddress() == null) {
            record.setRemoteHostAddress(connInfo.getRemoteHostAddress());
        }
        if (record.getHostIdentifier() == null) {
            record.setHostIdentifier(connInfo.getLocalHostName());
        }
    }
    if (record.getSessionIdentifier() == null && task != null) {
        record.setSessionIdentifier(task.getTaskIdentifier());
    }
    if (record.getDeltas() != null) {
        for (ObjectDeltaOperation<? extends ObjectType> objectDeltaOperation : record.getDeltas()) {
            ObjectDelta<? extends ObjectType> delta = objectDeltaOperation.getObjectDelta();
            final Map<String, PolyString> resolvedOids = new HashMap<>();
            Visitor namesResolver = new Visitor() {

                @Override
                public void visit(Visitable visitable) {
                    if (visitable instanceof PrismReferenceValue) {
                        PrismReferenceValue refVal = ((PrismReferenceValue) visitable);
                        String oid = refVal.getOid();
                        if (oid == null) {
                            // happen
                            return;
                        }
                        if (refVal.getTargetName() != null) {
                            resolvedOids.put(oid, refVal.getTargetName());
                            return;
                        }
                        if (resolvedOids.containsKey(oid)) {
                            // may
                            PolyString resolvedName = resolvedOids.get(oid);
                            // be
                            // null
                            refVal.setTargetName(resolvedName);
                            return;
                        }
                        if (refVal.getObject() != null) {
                            PolyString name = refVal.getObject().getName();
                            refVal.setTargetName(name);
                            resolvedOids.put(oid, name);
                            return;
                        }
                        if (repositoryService == null) {
                            LOGGER.warn("No repository, no OID resolution (for {})", oid);
                            return;
                        }
                        PrismObjectDefinition<? extends ObjectType> objectDefinition = null;
                        if (refVal.getTargetType() != null) {
                            objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByType(refVal.getTargetType());
                        }
                        Class<? extends ObjectType> objectClass = null;
                        if (objectDefinition != null) {
                            objectClass = objectDefinition.getCompileTimeClass();
                        }
                        if (objectClass == null) {
                            // the default
                            objectClass = ObjectType.class;
                        // (shouldn't be
                        // needed)
                        }
                        SelectorOptions<GetOperationOptions> getNameOnly = SelectorOptions.create(new ItemPath(ObjectType.F_NAME), GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
                        try {
                            PrismObject<? extends ObjectType> object = repositoryService.getObject(objectClass, oid, Arrays.asList(getNameOnly), new OperationResult("dummy"));
                            PolyString name = object.getName();
                            refVal.setTargetName(name);
                            resolvedOids.put(oid, name);
                            LOGGER.trace("Resolved {}: {} to {}", objectClass, oid, name);
                        } catch (ObjectNotFoundException e) {
                            LOGGER.trace("Couldn't determine the name for {}: {} as it does not exist", objectClass, oid, e);
                            resolvedOids.put(oid, null);
                        } catch (SchemaException | RuntimeException e) {
                            LOGGER.trace("Couldn't determine the name for {}: {} because of unexpected exception", objectClass, oid, e);
                            resolvedOids.put(oid, null);
                        }
                    }
                }
            };
            delta.accept(namesResolver);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Visitor(com.evolveum.midpoint.prism.Visitor) HashMap(java.util.HashMap) Visitable(com.evolveum.midpoint.prism.Visitable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LightweightIdentifier(com.evolveum.midpoint.task.api.LightweightIdentifier) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 98 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class ConsistencyTest method test270ModifyDiscoveryAddCommunicationProblem.

/**
	 * this test simulates situation, when someone tries to add account while
	 * resource is down and this account is created by next get call on this
	 * account
	 */
@Test
public void test270ModifyDiscoveryAddCommunicationProblem() throws Exception {
    final String TEST_NAME = "test270ModifyDiscoveryAddCommunicationProblem";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    openDJController.assumeStopped();
    OperationResult parentResult = new OperationResult(TEST_NAME);
    // WHEN
    repoAddObjectFromFile(USER_BOB_NO_GIVEN_NAME_FILENAME, parentResult);
    assertUserNoAccountRef(USER_BOB_NO_GIVEN_NAME_OID, parentResult);
    Task task = taskManager.createTaskInstance();
    //REQUEST_USER_MODIFY_ADD_ACCOUNT_COMMUNICATION_PROBLEM
    requestToExecuteChanges(REQUEST_USER_MODIFY_ASSIGN_ACCOUNT, USER_BOB_NO_GIVEN_NAME_OID, UserType.class, task, null, parentResult);
    parentResult.computeStatus();
    display("add object communication problem result: ", parentResult);
    assertEquals("Expected handled error but got: " + parentResult.getStatus(), OperationResultStatus.HANDLED_ERROR, parentResult.getStatus());
    String accountOid = assertUserOneAccountRef(USER_BOB_NO_GIVEN_NAME_OID);
    checkPostponedAccountWithAttributes(accountOid, "bob", null, "Dylan", "Bob Dylan", FailedOperationTypeType.ADD, false, task, parentResult);
    //start openDJ
    openDJController.start();
    //and set the resource availability status to UP
    modifyResourceAvailabilityStatus(AvailabilityStatusType.UP, parentResult);
    // WHEN
    // This should not throw exception
    modelService.getObject(ShadowType.class, accountOid, null, task, parentResult);
    OperationResult modifyGivenNameResult = new OperationResult("execute changes -> modify user's given name");
    LOGGER.trace("execute changes -> modify user's given name");
    Collection<? extends ItemDelta> givenNameDelta = PropertyDelta.createModificationReplacePropertyCollection(UserType.F_GIVEN_NAME, getUserDefinition(), new PolyString("Bob"));
    ObjectDelta familyNameD = ObjectDelta.createModifyDelta(USER_BOB_NO_GIVEN_NAME_OID, givenNameDelta, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> modifyFamilyNameDelta = MiscSchemaUtil.createCollection(familyNameD);
    modelService.executeChanges(modifyFamilyNameDelta, null, task, modifyGivenNameResult);
    modifyGivenNameResult.computeStatus();
    display("add object communication problem result: ", modifyGivenNameResult);
    assertEquals("Expected handled error but got: " + modifyGivenNameResult.getStatus(), OperationResultStatus.SUCCESS, modifyGivenNameResult.getStatus());
    PrismObject<ShadowType> bobRepoAcc = repositoryService.getObject(ShadowType.class, accountOid, null, modifyGivenNameResult);
    assertNotNull(bobRepoAcc);
    ShadowType bobRepoAccount = bobRepoAcc.asObjectable();
    displayJaxb("Shadow after discovery: ", bobRepoAccount, ShadowType.COMPLEX_TYPE);
    assertNull("Bob's account after discovery must not have failed opertion.", bobRepoAccount.getFailedOperationType());
    assertNull("Bob's account after discovery must not have result.", bobRepoAccount.getResult());
    assertNotNull("Bob's account must contain reference on the resource", bobRepoAccount.getResourceRef());
    checkNormalizedShadowWithAttributes(accountOid, "bob", "Bob", "Dylan", "Bob Dylan", false, task, parentResult);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 99 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class ConsistencyTest method test250ModifyObjectTwoTimesCommunicationProblem.

@Test
public void test250ModifyObjectTwoTimesCommunicationProblem() throws Exception {
    final String TEST_NAME = "test250ModifyObjectTwoTimesCommunicationProblem";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    openDJController.assumeStopped();
    OperationResult parentResult = new OperationResult(TEST_NAME);
    assertUserOneAccountRef(USER_JACK2_OID);
    Collection<PropertyDelta> modifications = new ArrayList<PropertyDelta>();
    PropertyDelta fullNameDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_FULL_NAME), getUserDefinition(), new PolyString("jackNew2"));
    modifications.add(fullNameDelta);
    PrismPropertyValue<ActivationStatusType> enabledUserAction = new PrismPropertyValue<ActivationStatusType>(ActivationStatusType.ENABLED, OriginType.USER_ACTION, null);
    PropertyDelta<ActivationStatusType> enabledDelta = PropertyDelta.createDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getUserDefinition());
    enabledDelta.addValueToAdd(enabledUserAction);
    modifications.add(enabledDelta);
    ObjectDelta objectDelta = ObjectDelta.createModifyDelta(USER_JACK2_OID, modifications, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
    Task task = taskManager.createTaskInstance();
    modelService.executeChanges(deltas, null, task, parentResult);
    parentResult.computeStatus();
    String accountOid = assertUserOneAccountRef(USER_JACK2_OID);
    PrismObject<ShadowType> account = modelService.getObject(ShadowType.class, accountOid, null, task, parentResult);
    assertNotNull(account);
    ShadowType shadow = account.asObjectable();
    assertNotNull(shadow.getObjectChange());
    display("shadow after communication problem", shadow);
    Collection<PropertyDelta> newModifications = new ArrayList<PropertyDelta>();
    PropertyDelta fullNameDeltaNew = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_FULL_NAME), getUserDefinition(), new PolyString("jackNew2a"));
    newModifications.add(fullNameDeltaNew);
    PropertyDelta givenNameDeltaNew = PropertyDelta.createModificationReplaceProperty(new ItemPath(UserType.F_GIVEN_NAME), getUserDefinition(), new PolyString("jackNew2a"));
    newModifications.add(givenNameDeltaNew);
    PrismPropertyValue<ActivationStatusType> enabledOutboundAction = new PrismPropertyValue<ActivationStatusType>(ActivationStatusType.ENABLED, OriginType.USER_ACTION, null);
    PropertyDelta<ActivationStatusType> enabledDeltaNew = PropertyDelta.createDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getUserDefinition());
    enabledDeltaNew.addValueToAdd(enabledOutboundAction);
    newModifications.add(enabledDeltaNew);
    ObjectDelta newObjectDelta = ObjectDelta.createModifyDelta(USER_JACK2_OID, newModifications, UserType.class, prismContext);
    Collection<ObjectDelta<? extends ObjectType>> newDeltas = MiscSchemaUtil.createCollection(newObjectDelta);
    modelService.executeChanges(newDeltas, null, task, parentResult);
    account = modelService.getObject(ShadowType.class, accountOid, null, task, parentResult);
    assertNotNull(account);
    shadow = account.asObjectable();
    assertNotNull(shadow.getObjectChange());
    display("shadow after communication problem", shadow);
//		parentResult.computeStatus();
//		assertEquals("expected handled error in the result", OperationResultStatus.HANDLED_ERROR, parentResult.getStatus());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 100 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class AuditTest method test100AuditSimple.

@Test
public void test100AuditSimple() throws Exception {
    LOGGER.info("===[ test100AuditSimple ]===");
    // WHEN
    AuditEventRecord record = new AuditEventRecord();
    record.addPropertyValue("prop1", "val1.1");
    record.addPropertyValue("prop1", "val1.2");
    record.addPropertyValue("prop2", "val2");
    record.addPropertyValue("prop3", null);
    AuditReferenceValue refVal1_1 = new AuditReferenceValue("oid1.1", UserType.COMPLEX_TYPE, new PolyString("user1.1"));
    AuditReferenceValue refVal1_2 = new AuditReferenceValue("oid1.2", RoleType.COMPLEX_TYPE, new PolyString("role1.2"));
    AuditReferenceValue refVal2 = new AuditReferenceValue("oid2", null, new PolyString("object2"));
    AuditReferenceValue refVal3 = new AuditReferenceValue();
    record.addReferenceValue("ref1", refVal1_1);
    record.addReferenceValue("ref1", refVal1_2);
    record.addReferenceValue("ref2", refVal2);
    record.addReferenceValue("ref3", refVal3);
    LOGGER.info("Adding audit record {}", record);
    auditService.audit(record, new SimpleTaskAdapter());
    // THEN
    System.out.println("Record written:\n" + record.debugDump());
    System.out.println("Repo ID: " + record.getRepoId());
    AuditEventRecord loaded = getAuditEventRecord(1, 0);
    System.out.println("Record loaded:\n" + loaded.debugDump());
    System.out.println("Repo ID: " + loaded.getRepoId());
    assertEquals("Wrong # of properties", 3, loaded.getProperties().size());
    assertEquals("Wrong prop1 values", new HashSet<>(Arrays.asList("val1.1", "val1.2")), loaded.getPropertyValues("prop1"));
    assertEquals("Wrong prop2 values", new HashSet<>(Collections.singletonList("val2")), loaded.getPropertyValues("prop2"));
    assertEquals("Wrong prop3 values", new HashSet<>(Collections.singletonList(null)), loaded.getPropertyValues("prop3"));
    assertEquals("Wrong # of references", 3, loaded.getReferences().size());
    assertEquals("Wrong ref1 values", new HashSet<>(Arrays.asList(refVal1_1, refVal1_2)), loaded.getReferenceValues("ref1"));
    assertEquals("Wrong ref2 values", new HashSet<>(Collections.singletonList(refVal2)), loaded.getReferenceValues("ref2"));
    assertEquals("Wrong ref3 values", new HashSet<>(Collections.singletonList(refVal3)), loaded.getReferenceValues("ref3"));
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) SimpleTaskAdapter(com.evolveum.midpoint.repo.sql.util.SimpleTaskAdapter) Test(org.testng.annotations.Test)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)168 Test (org.testng.annotations.Test)103 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)90 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)67 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)53 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)44 Task (com.evolveum.midpoint.task.api.Task)41 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 QName (javax.xml.namespace.QName)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)16 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)15 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)12 ArrayList (java.util.ArrayList)12 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 File (java.io.File)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)8 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)8