protected List<PrismObject> repoAddObjectsFromFile(File file, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, IOException { OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".addObjectsFromFile"); result.addParam("file", file.getPath()); LOGGER.trace("addObjectsFromFile: {}", file); List<PrismObject> objects = (List) prismContext.parserFor(file).parseObjects(); for (PrismObject object: objects) { try { repoAddObject(object, result); } catch (ObjectAlreadyExistsException e) { throw new ObjectAlreadyExistsException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (SchemaException e) { new SchemaException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (EncryptionException e) { new EncryptionException(e.getMessage()+" while adding "+object+" from file "+file, e); } } result.recordSuccess(); return objects; }
@Override protected void throwException(Exception cause, ProvisioningOperationState<? extends AsynchronousOperationResult> opState, OperationResult result) throws ObjectAlreadyExistsException { recordCompletionError(cause, opState, result); if (cause instanceof ObjectAlreadyExistsException) { throw (ObjectAlreadyExistsException)cause; } else { throw new ObjectAlreadyExistsException(cause.getMessage(), cause); } }
public static void assertExceptionSanity(ObjectAlreadyExistsException e) { LOGGER.debug("Exception (expected) {}", e, e); System.out.println("Exception (expected)"); System.out.println(ExceptionUtils.getFullStackTrace(e)); assert !e.getMessage().isEmpty() : "Empty exception message"; assert e.getMessage().length() < MAX_EXCEPTION_MESSAGE_LENGTH : "Exception message too long (" +e.getMessage().length()+" characters): "+e.getMessage(); }
public static void checkMaxIterations(int iteration, int maxIterations, String conflictMessage, String humanReadableName) throws ObjectAlreadyExistsException { if (iteration > maxIterations) { StringBuilder sb = new StringBuilder(); if (iteration == 1) { sb.append("Error processing "); } else { sb.append("Too many iterations (").append(iteration).append(") for "); } sb.append(humanReadableName); if (iteration == 1) { sb.append(": constraint violation: "); } else { sb.append(": cannot determine values that satisfy constraints: "); } if (conflictMessage != null) { sb.append(conflictMessage); } throw new ObjectAlreadyExistsException(sb.toString()); } }
taskManager.addTask((PrismObject<TaskType>) object, result); } catch (ObjectAlreadyExistsException ex) { result.recordFatalError(ex.getMessage(), ex); throw ex; } catch (SchemaException ex) { object.setOid(oid); } catch(ObjectAlreadyExistsException ex){ result.recordFatalError(ex.getMessage()+" while adding "+object+(contextDesc==null?"":" "+contextDesc), ex); throw ex; } catch(SchemaException ex){
protected <T extends ObjectType> List<PrismObject<T>> repoAddObjectsFromFile(File file, Class<T> type, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, IOException { OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".addObjectsFromFile"); result.addParam("file", file.getPath()); LOGGER.trace("addObjectsFromFile: {}", file); List<PrismObject<T>> objects = (List) prismContext.parserFor(file).parseObjects(); for (PrismObject<T> object: objects) { try { repoAddObject(object, result); } catch (ObjectAlreadyExistsException e) { throw new ObjectAlreadyExistsException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (SchemaException e) { new SchemaException(e.getMessage()+" while adding "+object+" from file "+file, e); } catch (EncryptionException e) { new EncryptionException(e.getMessage()+" while adding "+object+" from file "+file, e); } } result.recordSuccess(); return objects; }
Exception newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions(null, ex)); parentResult.recordFatalError("Object already exists: "+ex.getMessage(), newEx); return newEx; Exception newEx = null; if (e.getExplanation().contains("unique attribute conflict")){ newEx = new ObjectAlreadyExistsException(createMessageFromAllExceptions("Invalid attribute", ex)); } else{ newEx = new SchemaException(createMessageFromAllExceptions("Invalid attribute", ex));
public void deleteWorkersAndWorkState(String coordinatorTaskOid, long subtasksWaitTime, OperationResult result) throws SchemaException, ObjectNotFoundException { Task coordinatorTask = taskManager.getTask(coordinatorTaskOid, result); if (coordinatorTask.getKind() != TaskKindType.COORDINATOR) { throw new IllegalArgumentException("Task is not a coordinator task: " + coordinatorTask); } if (coordinatorTask.getExecutionStatus() == TaskExecutionStatus.WAITING) { throw new IllegalStateException("Couldn't delete workers and work state while operation is in progress (coordinator state is WAITING): " + coordinatorTask); } if (coordinatorTask.getExecutionStatus() == TaskExecutionStatus.RUNNABLE && coordinatorTask.getNodeAsObserved() != null) { throw new IllegalStateException("Couldn't delete workers and work state while operation is in progress (coordinator " + "state is RUNNABLE and it is executing on " + coordinatorTask.getNodeAsObserved() + "): " + coordinatorTask); } List<Task> subtasks = coordinatorTask.listSubtasks(true, result); taskManager.suspendAndDeleteTasks(TaskUtil.tasksToOids(subtasks), subtasksWaitTime, true, result); List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(TaskType.class) .item(TaskType.F_WORK_STATE).replace() .asItemDeltas(); try { taskManager.modifyTask(coordinatorTaskOid, itemDeltas, result); } catch (ObjectAlreadyExistsException e) { throw new IllegalStateException("Unexpected exception: " + e.getMessage(), e); } } }
"Couldn't add shadow object to the repository. Shadow object already exist. Reason: " + ex.getMessage(), ex); throw new ObjectAlreadyExistsException( "Couldn't add shadow object to the repository. Shadow object already exist. Reason: " + ex.getMessage(), ex);
private <T extends ObjectType> String nonOverwriteAddObjectAttempt(PrismObject<T> object, RObject rObject, String originalOid, Session session, OrgClosureManager.Context closureContext) throws ObjectAlreadyExistsException, SchemaException, DtoTranslationException { // check name uniqueness (by type) if (StringUtils.isNotEmpty(originalOid)) { LOGGER.trace("Checking oid uniqueness."); //todo improve this table name bullshit Class hqlType = ClassMapper.getHQLTypeClass(object.getCompileTimeClass()); NativeQuery query = session.createNativeQuery("select count(*) from " + RUtil.getTableName(hqlType, session) + " where oid=:oid"); query.setParameter("oid", object.getOid()); Number count = (Number) query.uniqueResult(); if (count != null && count.longValue() > 0) { throw new ObjectAlreadyExistsException("Object '" + object.getCompileTimeClass().getSimpleName() + "' with oid '" + object.getOid() + "' already exists."); } } updateFullObject(rObject, object); LOGGER.trace("Saving object (non overwrite)."); String oid = (String) session.save(rObject); lookupTableHelper.addLookupTableRows(session, rObject, false); caseHelper.addCertificationCampaignCases(session, rObject, false); if (closureManager.isEnabled()) { Collection<ReferenceDelta> modifications = createAddParentRefDelta(object); closureManager.updateOrgClosure(null, modifications, session, oid, object.getCompileTimeClass(), OrgClosureManager.Operation.ADD, closureContext); } return oid; }
@SuppressWarnings("unchecked") public Collection<ItemDelta> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, Collection<? extends ItemDelta> aprioriDeltas, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException { PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, resourceShadow.getOid(), null, result); Collection<ItemDelta> repoShadowChanges = new ArrayList<>(); computeUpdateShadowAttributeChanges(ctx, repoShadowChanges, resourceShadow, repoShadow); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Updating repo shadow {}:\n{}", resourceShadow.getOid(), DebugUtil.debugDump(repoShadowChanges)); } try { repositoryService.modifyObject(ShadowType.class, resourceShadow.getOid(), repoShadowChanges, result); } catch (ObjectAlreadyExistsException e) { // We are not renaming the object here. This should not happen. throw new SystemException(e.getMessage(), e); } return repoShadowChanges; }
result.computeStatus(); if (!result.isSuccess() && !result.isHandledError()) { ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Object already exist: " + ex.getMessage(), ex); } else { result.recordSuccess(); throw new ObjectAlreadyExistsException("Couldn't add object. Object already exists: " + ex.getMessage(), ex); } catch (EncryptionException e) {
constraintName = null; throw new ObjectAlreadyExistsException("Conflicting object already exists" + (constraintName == null ? "" : " (violated constraint '" + constraintName + "')"), constEx); } catch (ObjectAlreadyExistsException | SchemaException ex) {
parentResult.recordFatalError("Can't add " + foundShadow + " to the repository. Reason: " + e.getMessage(), e); throw new IllegalStateException(e.getMessage(), e);
+ ex.getMessage(), ex); } catch (ObjectAlreadyExistsException ex) { parentResult.recordFatalError("Conflict during modify: " + ex.getMessage(), ex); throw new ObjectAlreadyExistsException("Conflict during modify: " + ex.getMessage(), ex); } catch (SchemaException | ConfigurationException | ExpressionEvaluationException | SecurityViolationException | PolicyViolationException | RuntimeException | Error ex) { parentResult.recordFatalError(ex.getMessage(), ex);
throw new ObjectAlreadyExistsException(message, e);
public PrismObject<ShadowType> markShadowExists(PrismObject<ShadowType> repoShadow, OperationResult parentResult) throws SchemaException { List<ItemDelta<?, ?>> shadowChanges = prismContext.deltaFor(ShadowType.class) .item(ShadowType.F_EXISTS).replace(true) .asItemDeltas(); LOGGER.trace("Marking shadow {} as existent", repoShadow); try { repositoryService.modifyObject(ShadowType.class, repoShadow.getOid(), shadowChanges, parentResult); } catch (ObjectAlreadyExistsException e) { // Should not happen, this is not a rename new SystemException(e.getMessage(), e); } catch (ObjectNotFoundException e) { // Cannot be more dead LOGGER.trace("Attempt to mark shadow {} as existent found that no such shadow exists", repoShadow); return null; } ObjectDeltaUtil.applyTo(repoShadow, shadowChanges); return repoShadow; }
throw new GenericConnectorException("Generic error in connector: " + ex.getMessage(), ex); } catch (ObjectAlreadyExistsException ex){ result.recordFatalError("Could not create object on the resource. Object already exists on the resource: " + ex.getMessage(), ex); throw new ObjectAlreadyExistsException("Object already exists on the resource: " + ex.getMessage(), ex); } catch (ConfigurationException | SchemaException | SecurityViolationException | PolicyViolationException | RuntimeException | Error e){ result.recordFatalError(e);
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()); } }
+ " to the repository. Reason: " + e.getMessage(), e); throw new IllegalStateException(e.getMessage(), e); } catch (ObjectAlreadyExistsException e) { parentResult.recordFatalError( "Can't add " + newShadow + " to the repository. Reason: " + e.getMessage(), e); throw new IllegalStateException(e.getMessage(), e); } catch (ObjectNotFoundException e) { parentResult.recordWarning("Shadow " + newShadow + " was probably deleted from the repository in the meantime. Exception: "