private <T> void checkIfExist(Collection<T> valuesToDelete, Set<Object> currentValues) throws SchemaViolationException{ for (T valueToDelete : valuesToDelete) { boolean found = false; for (Object currentValue : currentValues) { if (resource.isCaseIgnoreValues() && currentValue instanceof String && valueToDelete instanceof String) { if (StringUtils.equalsIgnoreCase((String)currentValue, (String)valueToDelete)) { found = true; break; } } else { if (currentValue.equals(valueToDelete)) { found = true; break; } } } if (!found){ throw new SchemaViolationException("no such member: " + valueToDelete + " in " + currentValues); } } }
void breakIt(BreakMode breakMode, String operation) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException { if (breakMode == BreakMode.NONE) { return; } else if (breakMode == BreakMode.NETWORK) { throw new ConnectException("Network error (simulated error)"); } else if (breakMode == BreakMode.IO) { throw new FileNotFoundException("IO error (simulated error)"); } else if (breakMode == BreakMode.SCHEMA) { throw new SchemaViolationException("Schema violation (simulated error)"); } else if (breakMode == BreakMode.CONFLICT) { throw new ConflictException("Conflict (simulated error)"); } else if (breakMode == BreakMode.GENERIC) { // The connector will react with generic exception throw new IllegalArgumentException("Generic error (simulated error)"); } else if (breakMode == BreakMode.RUNTIME) { // The connector will just pass this up throw new IllegalStateException("Generic error (simulated error)"); } else if (breakMode == BreakMode.UNSUPPORTED) { throw new UnsupportedOperationException("Not supported (simulated error)"); } else if (breakMode == BreakMode.ASSERTION_ERROR) { throw new AssertionError("Assertion error"); } else { // This is a real error. Use this strange thing to make sure it passes up throw new RuntimeException("Unknown "+operation+" break mode "+getBreakMode); } }
throw new FileNotFoundException("IO error (simulated error)"); } else if (modifyBreakMode == BreakMode.SCHEMA) { throw new SchemaViolationException("Schema violation (simulated error)"); } else if (modifyBreakMode == BreakMode.CONFLICT) { throw new ConflictException("Conflict (simulated error)");
protected void checkSchema(String attrName, Collection<Object> values, String operationName) throws SchemaViolationException { if (resource == null || !resource.isEnforceSchema()) { return; } DummyObjectClass accountObjectClass; try { accountObjectClass = getObjectClass(); } catch (Exception e) { // No not enforce schema if the schema is broken (simulated) return; } if (accountObjectClass == null) { // Nothing to check return; } DummyAttributeDefinition attributeDefinition = getAttributeDefinition(attrName); if (attributeDefinition == null) { throw new SchemaViolationException("Attribute "+attrName+" is not defined in resource schema"); } if (attributeDefinition.isRequired() && (values == null || values.isEmpty())) { throw new SchemaViolationException(operationName + " of required attribute "+attrName+" results in no values"); } if (!attributeDefinition.isMulti() && values != null && values.size() > 1) { throw new SchemaViolationException(operationName + " of single-valued attribute "+attrName+" results in "+values.size()+" values"); } }