public static Collection<ResourceAttribute<?>> getSecondaryIdentifiers(Collection<? extends ResourceAttribute<?>> identifiers, ObjectClassComplexTypeDefinition objectClassDefinition) throws SchemaException { if (identifiers == null) { return null; } Collection<ResourceAttribute<?>> secondaryIdentifiers = new ArrayList<>(); for (ResourceAttribute<?> identifier: identifiers) { if (objectClassDefinition.isSecondaryIdentifier(identifier.getElementName())) { secondaryIdentifiers.add(identifier); } } return secondaryIdentifiers; }
public static boolean hasPrimaryIdentifier(Collection<? extends ResourceAttribute<?>> identifiers, ObjectClassComplexTypeDefinition objectClassDefinition) { for (ResourceAttribute identifier: identifiers) { if (objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) { return true; } } return false; }
private static void shortDumpShadowIdentifiers(StringBuilder sb, PrismObject<ShadowType> shadow, Collection<ResourceAttribute<?>> identifiers) { Iterator<ResourceAttribute<?>> iterator = identifiers.iterator(); while (iterator.hasNext()) { ResourceAttribute<?> identifier = iterator.next(); sb.append(identifier.getElementName().getLocalPart()); sb.append("="); sb.append(identifier.getRealValue()); if (iterator.hasNext()) { sb.append(";"); } } }
public static ResourceObjectIdentification createFromAttributes(ObjectClassComplexTypeDefinition objectClassDefinition, Collection<? extends ResourceAttribute<?>> attributes) throws SchemaException { Collection<? extends ResourceAttribute<?>> primaryIdentifiers = null; Collection<? extends ResourceAttribute<?>> secondaryIdentifiers = null; for (ResourceAttribute<?> identifier: attributes) { if (objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) { if (primaryIdentifiers == null) { primaryIdentifiers = new ArrayList<>(); } ((Collection)primaryIdentifiers).add(identifier); } else if (objectClassDefinition.isSecondaryIdentifier(identifier.getElementName())) { if (secondaryIdentifiers == null) { secondaryIdentifiers = new ArrayList<>(); } ((Collection)secondaryIdentifiers).add(identifier); } } return new ResourceObjectIdentification(objectClassDefinition, primaryIdentifiers, secondaryIdentifiers); }
public <T> boolean compareAttribute(RefinedObjectClassDefinition refinedObjectClassDefinition, ResourceAttribute<T> attributeA, T... valuesB) throws SchemaException { RefinedAttributeDefinition refinedAttributeDefinition = refinedObjectClassDefinition.findAttributeDefinition(attributeA.getElementName()); Collection<T> valuesA = getNormalizedAttributeValues(attributeA, refinedAttributeDefinition); return MiscUtil.unorderedCollectionEquals(valuesA, Arrays.asList(valuesB)); }
@Override public Collection<ResourceAttribute<?>> extractAttributesByDefinitions( Collection<? extends ResourceAttributeDefinition> definitions) { Collection<ResourceAttribute<?>> attributes = new ArrayList<>(definitions.size()); for (ResourceAttributeDefinition attrDef : definitions) { for (ResourceAttribute<?> property : getAttributes()){ if (attrDef.getName().equals(property.getElementName())){ property.setDefinition(attrDef); attributes.add(property); } } } return attributes; }
private Attribute convertToConnIdAttribute(ResourceAttribute<?> mpAttribute, ObjectClassComplexTypeDefinition ocDef) throws SchemaException { QName midPointAttrQName = mpAttribute.getElementName(); if (midPointAttrQName.equals(SchemaConstants.ICFS_UID)) { throw new SchemaException("ICF UID explicitly specified in attributes"); } String connIdAttrName = icfNameMapper.convertAttributeNameToConnId(mpAttribute, ocDef); Set<Object> connIdAttributeValues = new HashSet<>(); for (PrismPropertyValue<?> pval: mpAttribute.getValues()) { connIdAttributeValues.add(ConnIdUtil.convertValueToIcf(pval, protector, mpAttribute.getElementName())); } try { return AttributeBuilder.build(connIdAttrName, connIdAttributeValues); } catch (IllegalArgumentException e) { throw new SchemaException(e.getMessage(), e); } }
public <T> boolean compareAttribute(RefinedObjectClassDefinition refinedObjectClassDefinition, ResourceAttribute<T> attributeA, ResourceAttribute<T> attributeB) throws SchemaException { RefinedAttributeDefinition refinedAttributeDefinition = refinedObjectClassDefinition.findAttributeDefinition(attributeA.getElementName()); Collection<T> valuesA = getNormalizedAttributeValues(attributeA, refinedAttributeDefinition); refinedAttributeDefinition = refinedObjectClassDefinition.findAttributeDefinition(attributeA.getElementName()); Collection<T> valuesB = getNormalizedAttributeValues(attributeB, refinedAttributeDefinition); return MiscUtil.unorderedCollectionEquals(valuesA, valuesB); }
public String convertAttributeNameToConnId(ResourceAttribute<?> attribute, ObjectClassComplexTypeDefinition ocDef) throws SchemaException { ResourceAttributeDefinition attrDef = attribute.getDefinition(); if (attrDef == null) { attrDef = ocDef.findAttributeDefinition(attribute.getElementName()); if (attrDef == null) { throw new SchemaException("No attribute "+attribute.getElementName()+" in object class "+ocDef.getTypeName()); } } return convertAttributeNameToConnId(attrDef); }
private boolean matches(ResourceAttribute<?> identifier, ResourceAttribute<?> attributeToMatch, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { if (!identifier.getElementName().equals(attributeToMatch.getElementName())) { return false; } RefinedAttributeDefinition rAttrDef = rOcDef.findAttributeDefinition(identifier.getElementName()); QName matchingRuleQName = rAttrDef.getMatchingRuleQName(); if (matchingRuleQName == null || matchingRuleRegistry == null) { return identifier.equals(attributeToMatch, EquivalenceStrategy.REAL_VALUE); } MatchingRule<Object> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName()); return matchingRule.match(identifier.getRealValue(), attributeToMatch.getRealValue()); }
public void normalizeAttributes(PrismObject<ShadowType> shadow, RefinedObjectClassDefinition objectClassDefinition) throws SchemaException { for (ResourceAttribute<?> attribute: ShadowUtil.getAttributes(shadow)) { RefinedAttributeDefinition rAttrDef = objectClassDefinition.findAttributeDefinition(attribute.getElementName()); normalizeAttribute(attribute, rAttrDef); } }
@Override protected void checkConsistence(PrismObject<ShadowType> object, String elementDesc, String contextDesc) { super.checkConsistence(object, elementDesc, contextDesc); ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(object); if (attributesContainer != null) { ResourceType resource = getResource(); if (resource != null) { String resourceNamespace = ResourceTypeUtil.getResourceNamespace(resource); for(ResourceAttribute<?> attribute: attributesContainer.getAttributes()) { QName attrName = attribute.getElementName(); if (SchemaConstants.NS_ICF_SCHEMA.equals(attrName.getNamespaceURI())) { continue; } if (resourceNamespace.equals(attrName.getNamespaceURI())) { continue; } String desc = elementDesc+" in "+this + (contextDesc == null ? "" : " in " +contextDesc); throw new IllegalStateException("Invalid namespace for attribute "+attrName+" in "+desc); } } } }
private boolean hasAllIdentifiers(Collection<? extends ResourceAttribute<?>> attributes, RefinedObjectClassDefinition objectClassDefinition) { Collection<? extends RefinedAttributeDefinition> identifierDefs = objectClassDefinition.getPrimaryIdentifiers(); for (RefinedAttributeDefinition identifierDef: identifierDefs) { boolean found = false; for(ResourceAttribute<?> attribute: attributes) { if (attribute.getElementName().equals(identifierDef.getName()) && !attribute.isEmpty()) { found = true; } } if (!found) { return false; } } return true; }
private ResourceAttributeDefinition getUidDefinition(ResourceObjectIdentification identification) throws SchemaException { ResourceAttribute<String> primaryIdentifier = identification.getPrimaryIdentifier(); if (primaryIdentifier == null) { // fallback, compatibility for (ResourceAttribute<?> attr : identification.getAllIdentifiers()) { if (attr.getElementName().equals(SchemaConstants.ICFS_UID)) { return attr.getDefinition(); } } return null; } return primaryIdentifier.getDefinition(); }
private ResourceAttributeDefinition getNameDefinition(ResourceObjectIdentification identification) throws SchemaException { ResourceAttribute<String> secondaryIdentifier = identification.getSecondaryIdentifier(); if (secondaryIdentifier == null) { // fallback, compatibility for (ResourceAttribute<?> attr : identification.getAllIdentifiers()) { if (attr.getElementName().equals(SchemaConstants.ICFS_NAME)) { return attr.getDefinition(); } } return null; } return secondaryIdentifier.getDefinition(); }
private void replaceNameValue(ResourceObjectIdentification identification, Name newName) throws SchemaException { ResourceAttribute<String> secondaryIdentifier = identification.getSecondaryIdentifier(); if (secondaryIdentifier == null) { // fallback, compatibility for (ResourceAttribute<?> attr : identification.getAllIdentifiers()) { if (attr.getElementName().equals(SchemaConstants.ICFS_NAME)) { // expecting the NAME property is of type String //noinspection unchecked ((ResourceAttribute<String>) attr).setRealValue(newName.getNameValue()); return; } } throw new IllegalStateException("No identifiers"); } secondaryIdentifier.setRealValue(newName.getNameValue()); }
private void replaceUidValue(ResourceObjectIdentification identification, Uid newUid) throws SchemaException { ResourceAttribute<String> primaryIdentifier = identification.getPrimaryIdentifier(); if (primaryIdentifier == null) { // fallback, compatibility Collection<? extends ResourceAttribute<?>> identifiers = identification.getAllIdentifiers(); for (ResourceAttribute<?> attr : identifiers) { if (attr.getElementName().equals(SchemaConstants.ICFS_UID)) { // expecting the UID property is of type String //noinspection unchecked ((ResourceAttribute<String>) attr).setRealValue(newUid.getUidValue()); return; } } throw new IllegalStateException("No UID attribute in " + identifiers); } primaryIdentifier.setRealValue(newUid.getUidValue()); }
private String getEntryUuid(Collection<ResourceAttribute<?>> identifiers) { for (ResourceAttribute<?> identifier : identifiers) { if (identifier.getElementName().equals(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME))) { return identifier.getValue(String.class).getValue(); } } return null; }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void applyAfterOperationAttributes(PrismObject<ShadowType> shadow, Collection<ResourceAttribute<?>> resourceAttributesAfterAdd) throws SchemaException { if (resourceAttributesAfterAdd == null) { return; } ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow); for (ResourceAttribute attributeAfter : resourceAttributesAfterAdd) { ResourceAttribute attributeBefore = attributesContainer.findAttribute(attributeAfter.getElementName()); if (attributeBefore != null) { attributesContainer.remove(attributeBefore); } if (!attributesContainer.contains(attributeAfter)) { attributesContainer.add(attributeAfter.clone()); } } }
public static void assertAttributeDefinition(ResourceAttribute<?> attr, QName expectedType, int minOccurs, int maxOccurs, boolean canRead, boolean canCreate, boolean canUpdate, Class<?> expectedAttributeDefinitionClass) { ResourceAttributeDefinition definition = attr.getDefinition(); QName attrName = attr.getElementName(); assertNotNull("No definition for attribute "+attrName, definition); //assertEquals("Wrong class of definition for attribute"+attrName, expetcedAttributeDefinitionClass, definition.getClass()); assertTrue("Wrong class of definition for attribute"+attrName+" (expected: " + expectedAttributeDefinitionClass + ", real: " + definition.getClass() + ")", expectedAttributeDefinitionClass.isAssignableFrom(definition.getClass())); assertEquals("Wrong type in definition for attribute"+attrName, expectedType, definition.getTypeName()); assertEquals("Wrong minOccurs in definition for attribute"+attrName, minOccurs, definition.getMinOccurs()); assertEquals("Wrong maxOccurs in definition for attribute"+attrName, maxOccurs, definition.getMaxOccurs()); assertEquals("Wrong canRead in definition for attribute"+attrName, canRead, definition.canRead()); assertEquals("Wrong canCreate in definition for attribute"+attrName, canCreate, definition.canAdd()); assertEquals("Wrong canUpdate in definition for attribute"+attrName, canUpdate, definition.canModify()); }