use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.
the class AssignmentTablePanel method handleAssignmentDeltas.
public ContainerDelta handleAssignmentDeltas(ObjectDelta<T> userDelta, PrismContainerDefinition def, QName assignmentPath) throws SchemaException {
ContainerDelta assDelta = new ContainerDelta(new ItemPath(), assignmentPath, def, // hoping that def contains a prism
def.getPrismContext());
// context!
// PrismObject<OrgType> org =
// (PrismObject<OrgType>)getModel().getObject().getAssignmentParent();
// PrismObjectDefinition orgDef = org.getDefinition();
// PrismContainerDefinition assignmentDef =
// def.findContainerDefinition(assignmentPath);
List<AssignmentEditorDto> assignments = getAssignmentModel().getObject();
for (AssignmentEditorDto assDto : assignments) {
PrismContainerValue newValue = assDto.getNewValue(getPageBase().getPrismContext());
switch(assDto.getStatus()) {
case ADD:
newValue.applyDefinition(def, false);
assDelta.addValueToAdd(newValue.clone());
break;
case DELETE:
PrismContainerValue oldValue = assDto.getOldValue();
oldValue.applyDefinition(def);
assDelta.addValueToDelete(oldValue.clone());
break;
case MODIFY:
if (!assDto.isModified(getPageBase().getPrismContext())) {
LOGGER.trace("Assignment '{}' not modified.", new Object[] { assDto.getName() });
continue;
}
handleModifyAssignmentDelta(assDto, def, newValue, userDelta);
break;
default:
warn(getString("pageUser.message.illegalAssignmentState", assDto.getStatus()));
}
}
if (!assDelta.isEmpty()) {
assDelta = userDelta.addModification(assDelta);
}
// todo remove this block [lazyman] after model is updated - it has to
// remove resource from accountConstruction
Collection<PrismContainerValue> values = assDelta.getValues(PrismContainerValue.class);
for (PrismContainerValue value : values) {
AssignmentType ass = new AssignmentType();
ass.setupContainerValue(value);
removeResourceFromAccConstruction(ass);
}
return assDelta;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.
the class AbstractOrgClosureTest method registerObject.
protected void registerObject(ObjectType objectType, boolean registerChildrenLinks) {
if (!(objectType instanceof OrgType)) {
return;
}
String oid = objectType.getOid();
LOGGER.info("Registering {} into memory graph", oid);
registerVertexIfNeeded(oid);
for (ObjectReferenceType ort : objectType.getParentOrgRef()) {
registerVertexIfNeeded(ort.getOid());
try {
orgGraph.addEdge(oid, ort.getOid());
} catch (RuntimeException e) {
System.err.println("Couldn't add edge " + oid + " -> " + ort.getOid() + " into the graph");
throw e;
}
}
if (registerChildrenLinks) {
// let's check for existing children
List<String> children = getOrgChildren(oid);
LOGGER.info("Registering children of {}: {} into memory graph", oid, children);
for (String child : children) {
registerVertexIfNeeded(child);
orgGraph.addEdge(child, oid);
}
}
LOGGER.info("Registration of {} done.", oid);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.
the class AbstractOrgClosureTest method scanOrgStructure.
// // todo better name
// protected void prepareOrgStructureOids(int level, String parentOid, int[] orgChildrenInLevel, int[] userChildrenInLevel, int[] parentsInLevel, String oidPrefix,
// OperationResult result) throws Exception {
// if (level == orgChildrenInLevel.length) {
// return;
// }
//
// List<String> orgsAtThisLevel = getOrgsAtThisLevelSafe(level);
// for (int i = 0; i < orgChildrenInLevel[level]; i++) {
// String newOidPrefix = getOidCharFor(i) + oidPrefix;
// int numberOfParents = parentsInLevel==null ? (parentOid != null ? 1 : 0) : parentsInLevel[level];
// PrismObject<OrgType> org = createOrg(generateParentsForLevel(parentOid, level, numberOfParents), newOidPrefix);
// LOGGER.info("'Creating' {}, total {}; parents = {}", new Object[]{org, count, getParentsOids(org)});
// String oid = org.getOid();
// if (parentOid == null) {
// rootOids.add(oid);
// }
// allOrgCreated.add(org.asObjectable());
// registerObject(org.asObjectable(), false);
// orgsAtThisLevel.add(oid);
// count++;
//
// prepareOrgStructureOids(level + 1, oid, orgChildrenInLevel, userChildrenInLevel, parentsInLevel, newOidPrefix, result);
// }
//
// if (parentOid != null) {
//
// List<String> usersAtThisLevel = getUsersAtThisLevelSafe(level);
//
// for (int u = 0; u < userChildrenInLevel[level]; u++) {
// int numberOfParents = parentsInLevel==null ? 1 : parentsInLevel[level];
// PrismObject<UserType> user = createUser(generateParentsForLevel(parentOid, level, numberOfParents), getOidCharFor(u) + ":" + oidPrefix);
// LOGGER.info("'Creating' {}, total {}; parents = {}", new Object[]{user, count, getParentsOids(user)});
// String uoid = user.getOid();
// registerObject(user.asObjectable(), false);
// usersAtThisLevel.add(uoid);
// count++;
// }
// }
//
// }
protected void scanOrgStructure(OperationResult opResult) throws SchemaException, ObjectNotFoundException {
// determine rootOids
for (int i = 0; ; i++) {
String oid = "o" + createOid("" + getOidCharFor(i));
try {
System.out.println("Trying to find " + oid + " as a root");
OrgType org = repositoryService.getObject(OrgType.class, oid, null, opResult).asObjectable();
rootOids.add(org.getOid());
allOrgCreated.add(org);
registerOrgToLevels(0, org.getOid());
registerObject(org, false);
objectCount++;
} catch (ObjectNotFoundException e) {
break;
}
}
for (String rootOid : rootOids) {
scanChildren(0, rootOid, opResult);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.
the class AbstractOrgClosureTest method removeObjectParent.
protected void removeObjectParent(ObjectType object, ObjectReferenceType parentOrgRef, boolean useReplace, OperationResult opResult) throws Exception {
List<ItemDelta> modifications = new ArrayList<>();
if (!useReplace) {
// standard case
PrismReferenceValue existingValue = parentOrgRef.asReferenceValue();
ItemDelta removeParent = ReferenceDelta.createModificationDelete(object.getClass(), OrgType.F_PARENT_ORG_REF, prismContext, existingValue.clone());
modifications.add(removeParent);
} else {
// using REPLACE modification
List<PrismReferenceValue> newValues = new ArrayList<>();
for (ObjectReferenceType ort : object.getParentOrgRef()) {
if (!ort.getOid().equals(parentOrgRef.getOid())) {
newValues.add(ort.asReferenceValue().clone());
}
}
PrismObjectDefinition objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(object.getClass());
ItemDelta replaceParent = ReferenceDelta.createModificationReplace(new ItemPath(OrgType.F_PARENT_ORG_REF), objectDefinition, newValues);
modifications.add(replaceParent);
}
repositoryService.modifyObject(object.getClass(), object.getOid(), modifications, opResult);
if (object instanceof OrgType) {
orgGraph.removeEdge(object.getOid(), parentOrgRef.getOid());
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.
the class AbstractOrgClosureTest method checkOrgGraph.
// checks org graph w.r.t. real org/parentref situation in repo
protected void checkOrgGraph() throws SchemaException {
OperationResult result = new OperationResult("temp");
int numberOfOrgsInRepo = repositoryService.countObjects(OrgType.class, new ObjectQuery(), result);
info("Checking graph with repo. Orgs in repo: " + numberOfOrgsInRepo + ", orgs in graph: " + orgGraph.vertexSet().size());
assertTrue("# of orgs in repo (" + numberOfOrgsInRepo + ") is different from # of orgs in graph (" + orgGraph.vertexSet().size() + ")", numberOfOrgsInRepo == orgGraph.vertexSet().size());
for (String oid : orgGraph.vertexSet()) {
//info("Checking " + oid);
OrgType orgType = null;
try {
orgType = repositoryService.getObject(OrgType.class, oid, null, result).asObjectable();
} catch (ObjectNotFoundException | SchemaException e) {
throw new AssertionError("Couldn't fetch " + oid, e);
}
assertTrue(orgGraph.vertexSet().contains(orgType.getOid()));
Set<String> parentOidsInRepo = new HashSet<>();
for (ObjectReferenceType ort : orgType.getParentOrgRef()) {
if (orgGraph.vertexSet().contains(ort.getOid())) {
// i.e. the parent does exist
parentOidsInRepo.add(ort.getOid());
}
}
Set<String> parentOidsInGraph = new HashSet<>();
for (DefaultEdge edge : orgGraph.outgoingEdgesOf(oid)) {
parentOidsInGraph.add(orgGraph.getEdgeTarget(edge));
}
assertEquals("Unexpected parentRefOrg set in " + orgType, parentOidsInGraph, parentOidsInRepo);
}
info("Graph is OK w.r.t. repo");
}
Aggregations