Search in sources :

Example 16 with PrismReference

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

the class TestConnectorDummyFake method test100UpgradeModelAddDelete.

/**
	 * Upgrading connector in RESOURCE_DUMMY_FAKE by changing the connectorRef in resource (add/delete case)
	 * The connectorRef is changed from fake to real dummy.
	 */
@Test
public void test100UpgradeModelAddDelete() throws Exception {
    final String TEST_NAME = "test100UpgradeModelAddDelete";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<ResourceType> dummyResourceModelBefore = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result);
    ObjectDelta<ResourceType> resourceDelta = ObjectDelta.createEmptyModifyDelta(ResourceType.class, RESOURCE_DUMMY_FAKE_OID, prismContext);
    PrismReference connectorRef = resourceDummyFake.findReference(ResourceType.F_CONNECTOR_REF);
    ReferenceDelta connectorRefDeltaDel = ReferenceDelta.createModificationDelete(ResourceType.F_CONNECTOR_REF, getResourceDefinition(), connectorRef.getValue().clone());
    resourceDelta.addModification(connectorRefDeltaDel);
    ReferenceDelta connectorRefDeltaAdd = ReferenceDelta.createModificationAdd(ResourceType.F_CONNECTOR_REF, getResourceDefinition(), connectorDummyOid);
    resourceDelta.addModification(connectorRefDeltaAdd);
    // Purge the schema. New connector schema is not compatible.
    resourceDelta.addModificationReplaceContainer(ResourceType.F_SCHEMA);
    display("Delta", resourceDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(resourceDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    result.computeStatus();
    display("executeChanges result", result);
    TestUtil.assertSuccess("executeChanges result", result);
    assertUpgrade(dummyResourceModelBefore);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) PrismReference(com.evolveum.midpoint.prism.PrismReference) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 17 with PrismReference

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

the class MidPointAbstractDataSource method getFieldValue.

@Override
public Object getFieldValue(JRField jrField) throws JRException {
    // TODO Auto-generated method stub
    String fieldName = jrField.getName();
    if (fieldName.equals("oid")) {
        return currentObject.getOid();
    }
    Item i = currentObject.findItem(new QName(fieldName));
    if (i == null) {
        return null;
    }
    if (i instanceof PrismProperty) {
        if (i.isSingleValue()) {
            return ((PrismProperty) i).getRealValue();
        }
        return ((PrismProperty) i).getRealValues();
    } else if (i instanceof PrismReference) {
        if (i.isSingleValue()) {
            return ((PrismReference) i).getValue().asReferencable();
        }
        List<Referencable> refs = new ArrayList<Referencable>();
        for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
            refs.add(refVal.asReferencable());
        }
        return refs;
    } else if (i instanceof PrismContainer) {
        if (i.isSingleValue()) {
            return ((PrismContainer) i).getValue().asContainerable();
        }
        List<Containerable> containers = new ArrayList<Containerable>();
        for (Object pcv : i.getValues()) {
            if (pcv instanceof PrismContainerValue) {
                containers.add(((PrismContainerValue) pcv).asContainerable());
            }
        }
        return containers;
    } else
        throw new JRException("Could not get value of the fileld: " + fieldName);
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) JRException(net.sf.jasperreports.engine.JRException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Item(com.evolveum.midpoint.prism.Item) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ArrayList(java.util.ArrayList) List(java.util.List) Containerable(com.evolveum.midpoint.prism.Containerable) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 18 with PrismReference

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

the class PageSelfDashboard method createAssignmentItem.

private AssignmentItemDto createAssignmentItem(PrismObject<UserType> user, PrismContainerValue<AssignmentType> assignment, Task task, OperationResult result) {
    ActivationType activation = assignment.asContainerable().getActivation();
    if (activation != null && activation.getAdministrativeStatus() != null && !activation.getAdministrativeStatus().equals(ActivationStatusType.ENABLED)) {
        return null;
    }
    PrismReference targetRef = assignment.findReference(AssignmentType.F_TARGET_REF);
    if (targetRef == null || targetRef.isEmpty()) {
        // account construction
        PrismContainer construction = assignment.findContainer(AssignmentType.F_CONSTRUCTION);
        String name = null;
        String description = "";
        if (construction.getValue().asContainerable() != null && !construction.isEmpty()) {
            ConstructionType constr = (ConstructionType) construction.getValue().asContainerable();
            if (constr.getResourceRef() != null) {
                ObjectReferenceType resourceRef = constr.getResourceRef();
                PrismObject resource = WebModelServiceUtils.loadObject(ResourceType.class, resourceRef.getOid(), this, task, result);
                name = WebComponentUtil.getName(resource);
                description = constr.getDescription();
            }
        }
        return new AssignmentItemDto(AssignmentEditorDtoType.CONSTRUCTION, name, description, null);
    }
    PrismReferenceValue refValue = targetRef.getValue();
    PrismObject value = refValue.getObject();
    if (value == null) {
        // resolve reference
        value = WebModelServiceUtils.loadObject(ObjectType.class, refValue.getOid(), this, task, result);
    }
    if (value == null) {
        // we couldn't resolve assignment details
        return new AssignmentItemDto(null, null, null, null);
    }
    String name = WebComponentUtil.getDisplayNameOrName(value);
    AssignmentEditorDtoType type = AssignmentEditorDtoType.getType(value.getCompileTimeClass());
    String relation = refValue.getRelation() != null ? refValue.getRelation().getLocalPart() : null;
    return new AssignmentItemDto(type, name, getAssignmentDescription(value), relation);
}
Also used : AssignmentEditorDtoType(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDtoType) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) AssignmentItemDto(com.evolveum.midpoint.web.page.admin.home.dto.AssignmentItemDto)

Example 19 with PrismReference

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

the class RepositoryObjectDataProvider method createItem.

private DebugObjectItem createItem(PrismObject<? extends ObjectType> object, OperationResult result) {
    DebugObjectItem item = DebugObjectItem.createDebugObjectItem(object);
    if (ShadowType.class.isAssignableFrom(object.getCompileTimeClass())) {
        PrismReference ref = object.findReference(new ItemPath(ShadowType.F_RESOURCE_REF));
        if (ref == null || ref.getValue() == null) {
            return item;
        }
        PrismReferenceValue refValue = ref.getValue();
        String resourceOid = refValue.getOid();
        ResourceDescription desc = resourceCache.get(resourceOid);
        if (desc == null) {
            desc = loadDescription(resourceOid, result);
            resourceCache.put(resourceOid, desc);
        }
        item.setResourceName(desc.getName());
        item.setResourceType(desc.getType());
    }
    return item;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismReference(com.evolveum.midpoint.prism.PrismReference) DebugObjectItem(com.evolveum.midpoint.web.page.admin.configuration.dto.DebugObjectItem) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 20 with PrismReference

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

the class RepositoryObjectDataProvider method loadDescription.

private ResourceDescription loadDescription(String oid, OperationResult result) {
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ResourceType.F_CONNECTOR, GetOperationOptions.createResolve());
    OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESOURCE);
    subResult.addParam("oid", oid);
    PrismObject<ResourceType> resource = null;
    String type = null;
    try {
        resource = getModel().getObject(ResourceType.class, oid, options, getPage().createSimpleTask(OPERATION_LOAD_RESOURCE), subResult);
        PrismReference ref = resource.findReference(ResourceType.F_CONNECTOR_REF);
        if (ref != null && ref.getValue() != null) {
            PrismReferenceValue refValue = ref.getValue();
            if (refValue.getObject() != null) {
                PrismObject connector = refValue.getObject();
                PrismProperty<String> pType = connector.findProperty(ConnectorType.F_CONNECTOR_TYPE);
                if (pType != null && pType.getRealValue() != null) {
                    type = pType.getRealValue(String.class);
                }
            }
        }
        subResult.recordSuccess();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource for account", ex);
        subResult.recordFatalError("Couldn't load resource for account.");
    } finally {
        subResult.recomputeStatus();
    }
    return new ResourceDescription(oid, WebComponentUtil.getName(resource), type);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) PrismReference(com.evolveum.midpoint.prism.PrismReference) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Aggregations

PrismReference (com.evolveum.midpoint.prism.PrismReference)41 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)15 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)8 Task (com.evolveum.midpoint.task.api.Task)8 ArrayList (java.util.ArrayList)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 QName (javax.xml.namespace.QName)7 Test (org.testng.annotations.Test)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)5 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4