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