public <C extends Containerable> void validateContainerable(C value, Class<C> type) throws SchemaException { if (value == null) { throw new SchemaException("Null object as a result of repository get operation for " + type); } Class<? extends Containerable> realType = value.getClass(); if (!type.isAssignableFrom(realType)) { throw new SchemaException("Expected to find '" + type.getSimpleName() + "' but found '" + realType.getSimpleName()); } // TODO call check consistence if possible }
public <T> ResourceAttribute<T> getPrimaryIdentifier() throws SchemaException { if (primaryIdentifiers == null || primaryIdentifiers.isEmpty()) { return null; } if (primaryIdentifiers.size() > 1) { throw new SchemaException("More than one primary identifier in "+this); } return (ResourceAttribute<T>) primaryIdentifiers.iterator().next(); }
public <T> T toSingle(Collection<T> values) throws SchemaException { if (values == null || values.isEmpty()) { return null; } else if (values.size() > 1) { throw new SchemaException("Attempt to get single value from a multi-valued property"); } else { return values.iterator().next(); } }
@Override public T parse(QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException { ObjectMapper mapper = (ObjectMapper) parser.getCodec(); Class clazz = XsdTypeMapper.toJavaType(typeName); ObjectReader r = mapper.readerFor(clazz); try { return r.readValue(node); // TODO implement COMPAT mode } catch (IOException e) { throw new SchemaException("Cannot parse value: " + e.getMessage(), e); } }
public static ResourceAttribute<String> getSecondaryIdentifier(PrismObject<? extends ShadowType> shadow) throws SchemaException { Collection<ResourceAttribute<?>> secondaryIdentifiers = getSecondaryIdentifiers(shadow); if (secondaryIdentifiers == null || secondaryIdentifiers.isEmpty()) { return null; } if (secondaryIdentifiers.size() > 1) { throw new SchemaException("Too many secondary identifiers in "+shadow+": "+secondaryIdentifiers); } return (ResourceAttribute<String>) secondaryIdentifiers.iterator().next(); }
public static NonceCredentialsPolicyType getEffectiveNonceCredentialsPolicy(SecurityPolicyType securityPolicy) throws SchemaException { List<NonceCredentialsPolicyType> noncePolicies = getEffectiveNonceCredentialsPolicies(securityPolicy); if (CollectionUtils.isEmpty(noncePolicies)) { return null; } if (noncePolicies.size() > 1) { throw new SchemaException("More than one nonce policy"); } return noncePolicies.get(0); }
private void checkExtraElements(MapXNodeImpl clauseXMap, QName... expected) throws SchemaException { List<QName> expectedList = Arrays.asList(expected); for (Entry<QName, XNodeImpl> entry : clauseXMap.entrySet()) { if (!QNameUtil.contains(expectedList, entry.getKey())) { throw new SchemaException("Unexpected item " + entry.getKey() + ":" + (entry.getValue() != null ? entry.getValue().debugDump() : "null")); } } }
@NotNull private TaskWorkStateType getWorkState(Task task) throws SchemaException { if (task.getWorkState() != null) { return task.getWorkState(); } else { throw new SchemaException("No work state in task " + task); } }
public DeltaBuilder(Class<T> objectClass, PrismContext prismContext) throws SchemaException { this.objectClass = objectClass; this.prismContext = prismContext; containerCTD = prismContext.getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(this.objectClass); if (containerCTD == null) { throw new SchemaException("Couldn't find definition for complex type " + this.objectClass); } deltas = new ArrayList<>(); currentDelta = null; }
public static void validateRefinedSchema(RefinedResourceSchema refinedSchema, PrismObject<ResourceType> resource) throws SchemaException { Set<RefinedObjectClassDefinitionKey> discrs = new HashSet<>(); for (RefinedObjectClassDefinition rObjectClassDefinition: refinedSchema.getRefinedDefinitions()) { QName typeName = rObjectClassDefinition.getTypeName(); RefinedObjectClassDefinitionKey key = new RefinedObjectClassDefinitionKey(rObjectClassDefinition); if (discrs.contains(key)) { throw new SchemaException("Duplicate definition of object class "+key+" in resource schema of "+resource); } discrs.add(key); ResourceTypeUtil.validateObjectClassDefinition(rObjectClassDefinition, resource); } }
@NotNull @Override public PrismContainer<C> instantiate(QName elementName) throws SchemaException { if (isAbstract()) { throw new SchemaException("Cannot instantiate abstract definition "+this); } elementName = DefinitionUtil.addNamespaceIfApplicable(elementName, this.name); return new PrismContainerImpl<>(elementName, this, prismContext); }
private boolean isOperationResult(ItemDelta delta) throws SchemaException { ItemDefinition def = delta.getDefinition(); if (def == null) { throw new SchemaException("No definition in delta for item " + delta.getPath()); } return OperationResultType.COMPLEX_TYPE.equals(def.getTypeName()); }
private ListXNodeImpl parseElementContentToList(Element element) throws SchemaException { if (DOMUtil.hasApplicationAttributes(element)) { throw new SchemaException("List should have no application attributes: " + element); } return parseElementList(DOMUtil.listChildElements(element), true); }
@Override public <T extends ItemDefinition> T findItemDefinitionByFullPath(Class<? extends Objectable> objectClass, Class<T> defClass, QName... itemNames) throws SchemaException { PrismObjectDefinition objectDefinition = findObjectDefinitionByCompileTimeClass(objectClass); if (objectDefinition == null) { throw new SchemaException("No object definition for " + objectClass); } return (T) ((ItemDefinition) objectDefinition).findItemDefinition(ItemPath.create(itemNames), defClass); }
public static <V extends PrismContainerValue> void createParentIfNeeded(V value, ItemDefinition definition) throws SchemaException { if (value.getParent() != null) { return; } if (!(definition instanceof PrismContainerDefinition)) { throw new SchemaException("Missing or invalid definition for a PrismContainer: " + definition); } PrismContainerImpl<?> rv = (PrismContainerImpl) definition.instantiate(); rv.add(value); }
@Override public <T extends Containerable> void setExtensionContainerValue(QName containerName, T value) throws SchemaException { PrismContainerDefinition containerDef = getPrismContext().getSchemaRegistry() .findContainerDefinitionByElementName(containerName); if (containerDef == null) { throw new SchemaException("Unknown container item " + containerName); } ArrayList<PrismContainerValue<T>> values = new ArrayList<>(1); values.add(value.asPrismContainerValue()); processModificationBatched(setExtensionContainerAndPrepareDelta(containerName, containerDef, values)); }
private RoleSelectionSpecEntry getRoleSelectionSpecEq(EqualFilter<String> eqFilter) throws SchemaException { if (QNameUtil.match(RoleType.F_ROLE_TYPE, eqFilter.getElementName()) || QNameUtil.match(RoleType.F_SUBTYPE, eqFilter.getElementName())) { List<PrismPropertyValue<String>> ppvs = eqFilter.getValues(); if (ppvs.size() > 1) { throw new SchemaException("More than one value in roleType search filter"); } String roleType = ppvs.get(0).getValue(); RoleSelectionSpecEntry roleTypeDval = new RoleSelectionSpecEntry(roleType, roleType, null); return roleTypeDval; } return null; }
public void assertDefinitions(boolean tolarateRawValues, String sourceDescription) throws SchemaException { if (tolarateRawValues && isRaw()) { return; } if (definition == null) { throw new SchemaException("No definition in "+this+" in "+sourceDescription); } assertDefinitions(tolarateRawValues, valuesToAdd, "values to add in "+sourceDescription); assertDefinitions(tolarateRawValues, valuesToReplace, "values to replace in "+sourceDescription); assertDefinitions(tolarateRawValues, valuesToDelete, "values to delete in "+sourceDescription); }
public <T> void normalizeDelta(ItemDelta<PrismPropertyValue<T>,PrismPropertyDefinition<T>> delta, RefinedObjectClassDefinition objectClassDefinition) throws SchemaException { if (!delta.getPath().startsWithName(ShadowType.F_ATTRIBUTES)) { return; } RefinedAttributeDefinition rAttrDef = objectClassDefinition.findAttributeDefinition(delta.getElementName()); if (rAttrDef == null){ throw new SchemaException("Failed to normalize attribute: " + delta.getElementName()+ ". Definition for this attribute doesn't exist."); } normalizeDelta(delta, rAttrDef); }
public ResourceType getResource() throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException { if (resource == null) { if (getResourceOid() == null) { throw new SchemaException("Null resource OID "+getDesc()); } GetOperationOptions options = GetOperationOptions.createReadOnly(); resource = resourceManager.getResource(getResourceOid(), options, getTask(), parentResult).asObjectable(); updateResourceName(); } return resource; }