private List<TriggerType> getSortedTriggers(List<PrismContainerValue<TriggerType>> triggerCVals) { List<TriggerType> rv = new ArrayList<>(); triggerCVals.forEach(cval -> rv.add(cval.clone().asContainerable())); rv.sort(Comparator.comparingLong(t -> XmlTypeConverter.toMillis(t.getTimestamp()))); return rv; }
private boolean hasMetadata(PrismContainerValue<R> cVal) { for (Item<?, ?> item : cVal.getItems()) { QName itemName = item.getElementName(); if (itemName.equals(AbstractCredentialType.F_METADATA)) { return true; } } return false; }
private PrismValue fixEmptyContainerValue(PrismContainerValue pcv, ItemPath path, PrismObject objectOld) { if (pcv.getId() == null || CollectionUtils.isNotEmpty(pcv.getItems())) { return pcv; } PrismContainer oldContainer = objectOld.findContainer(path); if (oldContainer == null) { return pcv; } PrismContainerValue oldValue = oldContainer.getValue(pcv.getId()); return oldValue != null ? oldValue : pcv; }
public static <T> void assertPropertyValue(PrismContainerValue<?> containerValue, ItemPath propPath, T... realPropValues) { PrismProperty<T> property = containerValue.findProperty(propPath); assertNotNull("Property " + propPath + " not found in " + containerValue.getParent(), property); assertPropertyValueDesc(property, containerValue.getParent().toString(), realPropValues); }
public static <T extends PrismContainer<?>> T getContainer(PrismContainerValue parentValue, QName name) { Validate.notNull(parentValue, "Parent container value must not be null."); Validate.notNull(name, "QName must not be null."); try { PrismContainer container = parentValue.findContainer(name); if (container != null) { return (T) container; } else { return (T) parentValue.createDetachedSubItem(name, PrismContainerImpl.class, null, parentValue.isImmutable()); } } catch (SchemaException ex) { throw new SystemException(ex.getMessage(), ex); } }
public CompleteWorkItemActionType clone() { CompleteWorkItemActionType object = new CompleteWorkItemActionType(); PrismContainerValue value = asPrismContainerValue().clone(); object.setupContainerValue(value); return object; }
@SuppressWarnings("unused") // used by certification cases report public static List<String> getComments(PrismContainerValue<AccessCertificationCaseType> pcv) { List<String> rv = new ArrayList<>(); for (AccessCertificationWorkItemType workItem : pcv.asContainerable().getWorkItem()) { if (!StringUtils.isEmpty(WorkItemTypeUtil.getComment(workItem))) { rv.add(WorkItemTypeUtil.getComment(workItem)); } } return rv; }
public static void mergeExtension(PrismContainerValue<?> dstExtensionContainerValue, PrismContainerValue<?> srcExtensionContainerValue) throws SchemaException { for (Item<?,?> srcExtensionItem: emptyIfNull(srcExtensionContainerValue.getItems())) { Item<?,?> magicItem = dstExtensionContainerValue.findItem(srcExtensionItem.getElementName()); if (magicItem == null) { //noinspection unchecked dstExtensionContainerValue.add(srcExtensionItem.clone()); } } }
private void checkContainerValuesSize(QName parentName, PrismContainerValue newValue, PrismContainerValue oldValue) { LOGGER.info("Checking: " + parentName); AssertJUnit.assertEquals("Count doesn't match for '" + parentName + "' id="+newValue.getId(), size(oldValue), size(newValue)); List<QName> checked = new ArrayList<>(); for (Item item : (List<Item>) newValue.getItems()) { if (!(item instanceof PrismContainer)) { continue; } PrismContainer newContainer = (PrismContainer) item; PrismContainer oldContainer = oldValue.findContainer(newContainer.getElementName()); AssertJUnit.assertNotNull("Container '" + newContainer.getElementName() + "' doesn't exist.", oldContainer); checkContainersSize(newContainer, oldContainer); checked.add(oldContainer.getElementName()); } for (Item item : (List<Item>) oldValue.getItems()) { if (!(item instanceof PrismContainer) || checked.contains(item.getElementName())) { continue; } PrismContainer oldContainer = (PrismContainer) item; PrismContainer newContainer = newValue.findContainer(oldContainer.getElementName()); checkContainersSize(newContainer, oldContainer); } }
private void checkSchema(AssignmentPathSegmentImpl segment, EvaluationContext ctx) throws SchemaException { AssignmentType assignmentType = getAssignmentType(segment, ctx); PrismContainerValue<AssignmentType> assignmentContainerValue = assignmentType.asPrismContainerValue(); PrismContainerable<AssignmentType> assignmentContainer = assignmentContainerValue.getParent(); if (assignmentContainer == null) { throw new SchemaException("The assignment "+assignmentType+" does not have a parent in "+segment.sourceDescription); } if (assignmentContainer.getDefinition() == null) { throw new SchemaException("The assignment "+assignmentType+" does not have definition in "+segment.sourceDescription); } PrismContainer<Containerable> extensionContainer = assignmentContainerValue.findContainer(AssignmentType.F_EXTENSION); if (extensionContainer != null) { if (extensionContainer.getDefinition() == null) { throw new SchemaException("Extension does not have a definition in assignment "+assignmentType+" in "+segment.sourceDescription); } for (Item<?,?> item: extensionContainer.getValue().getItems()) { if (item == null) { throw new SchemaException("Null item in extension in assignment "+assignmentType+" in "+segment.sourceDescription); } if (item.getDefinition() == null) { throw new SchemaException("Item "+item+" has no definition in extension in assignment "+assignmentType+" in "+segment.sourceDescription); } } } }
private Collection findItemValues(Long id, ItemPath path, Collection<PrismContainerValue<V>> cvalues) { if (cvalues == null) { return null; } boolean foundValuesOnPath = false; Collection<PrismValue> subValues = new ArrayList<>(); for (PrismContainerValue<V> cvalue: cvalues) { if (id == null || id.equals(cvalue.getId())) { Item<?,?> item = cvalue.findItem(path); if (item != null) { subValues.addAll(PrismValueCollectionsUtil.cloneCollection(item.getValues())); foundValuesOnPath = true; } } } return foundValuesOnPath ? subValues : null; }
/** * Finds a specific attribute in the resource object by definition. * * Returns null if nothing is found. * * @param attributeDefinition * attribute definition to find. * @return found attribute or null */ @Override public <X> ResourceAttribute<X> findAttribute(ResourceAttributeDefinition attributeDefinition) { return (ResourceAttribute<X>) getValue().findProperty(attributeDefinition); }
public PrismContainerValueAsserter<C,RA> assertItems(QName... expectedItems) { for (QName expectedItem: expectedItems) { Item<PrismValue,ItemDefinition> item = getPrismValue().findItem(ItemName.fromQName(expectedItem)); if (item == null) { fail("Expected item "+expectedItem+" in "+desc()+" but there was none. Items present: "+presentItemNames()); } } for (Item<?, ?> existingItem : getPrismValue().getItems()) { if (!QNameUtil.contains(expectedItems, existingItem.getElementName())) { fail("Unexpected item "+existingItem.getElementName()+" in "+desc()+". Expected items: "+QNameUtil.prettyPrint(expectedItems)); } } return this; }
private void preprocessEntitlement(ProvisioningContext ctx, PrismContainerValue<ShadowAssociationType> association, String desc, OperationResult result) throws SchemaException, ObjectNotFoundException, ConfigurationException, CommunicationException, ExpressionEvaluationException { PrismContainer<Containerable> identifiersContainer = association .findContainer(ShadowAssociationType.F_IDENTIFIERS); if (identifiersContainer != null && !identifiersContainer.isEmpty()) { // We already have identifiers here return; } ShadowAssociationType associationType = association.asContainerable(); if (associationType.getShadowRef() == null || StringUtils.isEmpty(associationType.getShadowRef().getOid())) { throw new SchemaException( "No identifiers and no OID specified in entitlements association " + association); } PrismObject<ShadowType> repoShadow; try { repoShadow = repositoryService.getObject(ShadowType.class, associationType.getShadowRef().getOid(), null, result); } catch (ObjectNotFoundException e) { throw new ObjectNotFoundException(e.getMessage() + " while resolving entitlement association OID in " + association + " in " + desc, e); } shadowCaretaker.applyAttributesDefinition(ctx, repoShadow); transplantIdentifiers(association, repoShadow); }
private Collection<PrismValue> cleanContainerIds(Collection<PrismValue> pvals) { if (pvals == null) { return null; } for (PrismValue pval: pvals) { if (pval instanceof PrismContainerValue<?>) { ((PrismContainerValue)pval).setId(null); } } return pvals; }
<IV extends PrismValue,ID extends ItemDefinition, I extends Item<IV,ID>> I findItem(ItemDefinition itemDefinition, Class<I> type);
@Override public boolean containsEquivalentValue(PrismContainerValue<C> value, @Nullable Comparator<PrismContainerValue<C>> comparator) { if (value.isIdOnly()) { return findValue(value.getId()) != null; } else { return contains(value, EquivalenceStrategy.IGNORE_METADATA_CONSIDER_DIFFERENT_IDS, comparator); } }
/** * Convenience method. Works only on single-valued containers. */ public void add(Item<?,?> item) throws SchemaException { checkMutability(); this.getValue().add(item); }
@Override protected void dumpValues(StringBuilder sb, String label, Collection<PrismContainerValue<V>> values, int indent) { DebugUtil.debugDumpLabel(sb, label, indent); if (values == null) { sb.append(" (null)"); } else if (values.isEmpty()) { sb.append(" (empty)"); } else { for (PrismContainerValue<V> val: values) { sb.append("\n"); sb.append(val.debugDump(indent+1)); } } }