private void generateIdForObject( PrismObject object, IdGeneratorResult result, Operation operation) { if (object == null) { return; } List<PrismContainer> containers = getChildrenContainers(object); Set<Long> usedIds = new HashSet<>(); for (PrismContainer c : containers) { if (c == null || c.getValues() == null) { continue; } for (PrismContainerValue val : (List<PrismContainerValue>) c.getValues()) { if (val.getId() != null) { usedIds.add(val.getId()); } } } Long nextId = 1L; for (PrismContainer c : containers) { if (c == null || c.getValues() == null) { continue; } for (PrismContainerValue val : (List<PrismContainerValue>) c.getValues()) { if (val.getId() != null) { if (Operation.ADD.equals(operation)) { result.getValues().add(val); } continue; } while (usedIds.contains(nextId)) { nextId++; } val.setId(nextId); usedIds.add(nextId); if (!Operation.ADD_WITH_OVERWRITE.equals(operation) && !Operation.MODIFY.equals(operation)) { result.getValues().add(val); } } } }
private CallableResult<List<AssignmentItemDto>> loadAssignments() throws Exception { LOGGER.debug("Loading assignments."); CallableResult callableResult = new CallableResult(); List<AssignmentItemDto> list = new ArrayList<AssignmentItemDto>(); callableResult.setValue(list); PrismObject<UserType> user = principalModel.getObject(); if (user == null || user.findContainer(UserType.F_ASSIGNMENT) == null) { return callableResult; } Task task = createSimpleTask(OPERATION_LOAD_ASSIGNMENTS); OperationResult result = task.getResult(); callableResult.setResult(result); PrismContainer assignments = user.findContainer(UserType.F_ASSIGNMENT); List<PrismContainerValue> values = assignments.getValues(); for (PrismContainerValue assignment : values) { AssignmentItemDto item = createAssignmentItem(user, assignment, task, result); if (item != null) { list.add(item); } } result.recordSuccessIfUnknown(); result.recomputeStatus(); Collections.sort(list); LOGGER.debug("Finished assignments loading."); return callableResult; }
private void cleanupEmptyContainers(PrismContainer container) { List<PrismContainerValue> values = container.getValues(); List<PrismContainerValue> valuesToBeRemoved = new ArrayList<PrismContainerValue>(); for (PrismContainerValue value : values) { List<? extends Item> items = value.getItems(); if (items != null) { Iterator<? extends Item> iterator = items.iterator(); while (iterator.hasNext()) { Item item = iterator.next(); if (item instanceof PrismContainer) { cleanupEmptyContainers((PrismContainer) item); if (item.isEmpty()) { iterator.remove(); } } } } if (items == null || value.isEmpty()) { valuesToBeRemoved.add(value); } } container.removeAll(valuesToBeRemoved); }