public PrismObject getConflictingShadow() { return constraintsCheckingResult.getConflictingShadow(); }
public String getMessages() { return constraintsCheckingResult.getMessages(); }
public ConstraintsCheckingResult check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { constraintsCheckingResult = new ConstraintsCheckingResult(); constraintsCheckingResult.setSatisfiesConstraints(true); PrismContainer<?> attributesContainer = shadowObject.findContainer(ShadowType.F_ATTRIBUTES); if (attributesContainer == null) { // No attributes no constraint violations LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness."); return constraintsCheckingResult; } RefinedObjectClassDefinition objectClassDefinition = provisioningContext.getObjectClassDefinition(); Collection<? extends ResourceAttributeDefinition> uniqueAttributeDefs = MiscUtil.unionExtends(objectClassDefinition.getPrimaryIdentifiers(), objectClassDefinition.getSecondaryIdentifiers()); LOGGER.trace("Checking uniquenss of attributes: {}", uniqueAttributeDefs); for (ResourceAttributeDefinition attrDef: uniqueAttributeDefs) { PrismProperty<?> attr = attributesContainer.findProperty(attrDef.getName()); LOGGER.trace("Attempt to check uniqueness of {} (def {})", attr, attrDef); if (attr == null) { continue; } constraintsCheckingResult.getCheckedAttributes().add(attr.getElementName()); boolean unique = checkAttributeUniqueness(attr, objectClassDefinition, provisioningContext.getResource(), shadowOid, task, result); if (!unique) { LOGGER.debug("Attribute {} conflicts with existing object (in {})", attr, provisioningContext.getShadowCoordinates()); constraintsCheckingResult.getConflictingAttributes().add(attr.getElementName()); constraintsCheckingResult.setSatisfiesConstraints(false); } } constraintsCheckingResult.setMessages(messageBuilder.toString()); return constraintsCheckingResult; }
confirmer, task, result); if (constraintsCheckingResult.isSatisfiesConstraints()) { satisfiesConstraints = true; return; for (QName checkedAttributeName: constraintsCheckingResult.getCheckedAttributes()) { if (constraintsCheckingResult.getConflictingAttributes().contains(checkedAttributeName)) { if (isInDelta(checkedAttributeName, projectionContext.getPrimaryDelta())) { throw new ObjectAlreadyExistsException("Attribute "+checkedAttributeName+" conflicts with existing object (and it is present in primary "+
private void checkConstraints(ProvisioningContext ctx, PrismObject<ShadowType> shadow, ProvisioningOperationState<AsynchronousOperationReturnValue<PrismObject<ShadowType>>> opState, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, ObjectAlreadyExistsException, SecurityViolationException { ShadowCheckType shadowConstraintsCheck = ResourceTypeUtil.getShadowConstraintsCheck(ctx.getResource()); if (shadowConstraintsCheck == ShadowCheckType.NONE) { return; } String shadowOid = shadow.getOid(); if (opState.getRepoShadow() != null) { shadowOid = opState.getRepoShadow().getOid(); } ConstraintsChecker checker = new ConstraintsChecker(); checker.setRepositoryService(repositoryService); checker.setShadowCache(this); checker.setPrismContext(prismContext); checker.setProvisioningContext(ctx); checker.setShadowObject(shadow); checker.setShadowOid(shadowOid); checker.setConstraintViolationConfirmer(conflictingShadowCandidate -> !Boolean.TRUE.equals(conflictingShadowCandidate.asObjectable().isDead()) ); checker.setUseCache(false); ConstraintsCheckingResult retval = checker.check(task, result); LOGGER.trace("Checked {} constraints, result={}", shadow, retval.isSatisfiesConstraints()); if (!retval.isSatisfiesConstraints()) { throw new ObjectAlreadyExistsException("Conflicting shadow already exists on "+ctx.getResource()); } }
constraintsCheckingResult.setConflictingShadow(foundObjects.get(0));