use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ConsistencyTest method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
* @throws Exception
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
final String TEST_NAME = "test511AssignAccountMorgan";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
openDJController.assumeRunning();
Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
//prepare new OU in opendj
Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
JAXBElement val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ModelWebServiceTest method nonExistingUidModify.
@Test(expectedExceptions = FaultMessage.class)
public void nonExistingUidModify() throws FaultMessage, ObjectNotFoundException, SchemaException, JAXBException, IOException {
final String oid = "1";
ObjectDeltaType objectDeltaType = new ObjectDeltaType();
objectDeltaType.setChangeType(ChangeTypeType.MODIFY);
objectDeltaType.setObjectType(UserType.COMPLEX_TYPE);
objectDeltaType.setOid(oid);
ItemDeltaType mod1 = new ItemDeltaType();
mod1.setModificationType(ModificationTypeType.ADD);
// ItemDeltaType.Value value = new ItemDeltaType.Value();
// value.getAny().add(DOMUtil.createElement(DOMUtil.getDocument(), new QName(SchemaConstants.NS_C, "fullName")));
mod1.setPath(new ItemPathType(new ItemPath(UserType.F_FULL_NAME)));
objectDeltaType.getItemDelta().add(mod1);
when(repositoryService.getObject(any(Class.class), eq(oid), any(Collection.class), any(OperationResult.class))).thenThrow(new ObjectNotFoundException("Oid '" + oid + "' not found."));
final UserType user = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
setSecurityContext(user);
ObjectDeltaListType deltaListType = new ObjectDeltaListType();
deltaListType.getDelta().add(objectDeltaType);
try {
modelService.executeChanges(deltaListType, null);
} catch (FaultMessage ex) {
ModelTUtil.assertObjectNotFoundFault(ex);
} finally {
SecurityContextHolder.getContext().setAuthentication(null);
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class TestModelWebServiceNegative method createShadowReplaceChange.
// TODO: more negative tests
private ObjectDeltaType createShadowReplaceChange(String oid, String path, final String value, QName type) {
ObjectDeltaType objectChange = new ObjectDeltaType();
objectChange.setOid(oid);
objectChange.setChangeType(ChangeTypeType.MODIFY);
objectChange.setObjectType(ObjectTypes.SHADOW.getTypeQName());
ItemDeltaType itemDeltaType = new ItemDeltaType();
itemDeltaType.setModificationType(ModificationTypeType.REPLACE);
ItemPathType itemPath = new ItemPathType(path);
itemDeltaType.setPath(itemPath);
PrimitiveXNode<String> xnode = new PrimitiveXNode<>();
ValueParser<String> valueParser = new ValueParser<String>() {
@Override
public String parse(QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException {
return value;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public String getStringValue() {
return value;
}
@Override
public Map<String, String> getPotentiallyRelevantNamespaces() {
throw new UnsupportedOperationException();
}
};
xnode.setValueParser(valueParser);
if (type != null) {
xnode.setExplicitTypeDeclaration(true);
xnode.setTypeQName(type);
}
RawType rawValue = new RawType(xnode, prismContext);
itemDeltaType.getValue().add(rawValue);
objectChange.getItemDelta().add(itemDeltaType);
return objectChange;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class PagingConvertor method createPagingType.
public static PagingType createPagingType(ObjectPaging paging) {
if (paging == null) {
return null;
}
PagingType pagingType = new PagingType();
pagingType.setOrderDirection(toOrderDirectionType(paging.getDirection()));
pagingType.setMaxSize(paging.getMaxSize());
pagingType.setOffset(paging.getOffset());
if (paging.getOrderBy() != null) {
pagingType.setOrderBy(new ItemPathType(paging.getOrderBy()));
}
return pagingType;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class MidPointDataSource method getFieldValue.
@Override
public Object getFieldValue(JRField jrField) throws JRException {
String fieldName = jrField.getName();
if (fieldName.equals("oid")) {
if (currentObject.getParent() instanceof PrismObject) {
return ((PrismObject) currentObject.getParent()).getOid();
} else {
throw new IllegalStateException("oid property is not supported for " + currentObject.getClass());
}
} else if (PARENT_NAME.equals(fieldName)) {
PrismContainerable parent1 = currentObject.getParent();
if (!(parent1 instanceof PrismContainer)) {
return null;
}
return ((PrismContainer) parent1).getParent();
} else if (THIS_NAME.equals(fieldName)) {
return currentObject;
}
ItemPathType itemPathType = new ItemPathType(fieldName);
ItemPath path = itemPathType.getItemPath();
Item i = currentObject.findItem(path);
if (i == null) {
return null;
}
if (i instanceof PrismProperty) {
if (i.isSingleValue()) {
return normalize(((PrismProperty) i).getRealValue(), jrField.getValueClass());
}
List normalized = new ArrayList<>();
for (Object real : ((PrismProperty) i).getRealValues()) {
normalized.add(normalize(real, jrField.getValueClass()));
}
return ((PrismProperty) i).getRealValues();
} else if (i instanceof PrismReference) {
if (i.isSingleValue()) {
return ObjectTypeUtil.createObjectRef(((PrismReference) i).getValue());
}
List<Referencable> refs = new ArrayList<Referencable>();
for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
refs.add(ObjectTypeUtil.createObjectRef(refVal));
}
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);
// return
// throw new UnsupportedOperationException("dataSource.getFiledValue() not supported");
}
Aggregations