use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ModelCrudService method addObject.
/**
* <p>
* Add new object.
* </p>
* <p>
* The OID provided in the input message may be empty. In that case the OID
* will be assigned by the implementation of this method and it will be
* provided as return value.
* </p>
* <p>
* This operation should fail if such object already exists (if object with
* the provided OID already exists).
* </p>
* <p>
* The operation may fail if provided OID is in an unusable format for the
* storage. Generating own OIDs and providing them to this method is not
* recommended for normal operation.
* </p>
* <p>
* Should be atomic. Should not allow creation of two objects with the same
* OID (even if created in parallel).
* </p>
* <p>
* The operation may fail if the object to be created does not conform to
* the underlying schema of the storage system or the schema enforced by the
* implementation.
* </p>
*
* @param object
* object to create
* @param parentResult
* parent OperationResult (in/out)
* @return OID assigned to the created object
* @throws ObjectAlreadyExistsException
* object with specified identifiers already exists, cannot add
* @throws ObjectNotFoundException
* object required to complete the operation was not found (e.g.
* appropriate connector or resource definition)
* @throws SchemaException
* error dealing with resource schema, e.g. created object does
* not conform to schema
* @throws ExpressionEvaluationException
* evaluation of expression associated with the object has failed
* @throws CommunicationException
* @throws ConfigurationException
* @throws PolicyViolationException
* Policy violation was detected during processing of the object
* @throws IllegalArgumentException
* wrong OID format, etc.
* @throws SystemException
* unknown error from underlying layers or other unexpected
* state
*/
public <T extends ObjectType> String addObject(PrismObject<T> object, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
Validate.notNull(object, "Object must not be null.");
Validate.notNull(parentResult, "Result type must not be null.");
object.checkConsistence();
T objectType = object.asObjectable();
prismContext.adopt(objectType);
OperationResult result = parentResult.createSubresult(ADD_OBJECT);
result.addParams(new String[] { "object" }, object);
Utils.resolveReferences(object, repository, false, false, EvaluationTimeType.IMPORT, true, prismContext, result);
String oid;
RepositoryCache.enter();
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Entering addObject with {}", object);
LOGGER.trace(object.debugDump());
}
if (options == null) {
if (StringUtils.isNotEmpty(objectType.getVersion())) {
options = ModelExecuteOptions.createOverwrite();
}
}
ObjectDelta<T> objectDelta = ObjectDelta.createAddDelta(object);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
modelService.executeChanges(deltas, options, task, result);
oid = objectDelta.getOid();
result.computeStatus();
result.cleanupResult();
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | SecurityViolationException | ConfigurationException | RuntimeException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} finally {
RepositoryCache.exit();
}
return oid;
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class TestEditSchema method test156LookupLanguagesAddRowExistingKey.
@Test
public void test156LookupLanguagesAddRowExistingKey() throws Exception {
final String TEST_NAME = "test156LookupLanguagesAddRowExistingKey";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
LookupTableRowType row = new LookupTableRowType();
row.setKey("gi_HU");
row.setValue("gi");
row.setLabel(PrismTestUtil.createPolyStringType("Humbug"));
ObjectDelta<LookupTableType> delta = ObjectDelta.createModificationAddContainer(LookupTableType.class, LOOKUP_LANGUAGES_OID, LookupTableType.F_ROW, prismContext, row);
// WHEN
TestUtil.displayWhen(TEST_NAME);
boolean exception = false;
try {
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
} catch (ObjectAlreadyExistsException ex) {
exception = true;
}
// as per description in https://wiki.evolveum.com/display/midPoint/Development+with+LookupTable
AssertJUnit.assertFalse(exception);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
result = task.getResult();
PrismObject<LookupTableType> lookup = getLookupTableAll(LOOKUP_LANGUAGES_OID, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
IntegrationTestTools.display("Languages", lookup);
assertEquals("Wrong lang lookup name", LOOKUP_LANGUAGES_NAME, lookup.asObjectable().getName().getOrig());
PrismContainer<LookupTableRowType> tableContainer = lookup.findContainer(LookupTableType.F_ROW);
assertNotNull("Table container missing", tableContainer);
assertEquals("Unexpected table container size", 7, tableContainer.size());
assertLookupRow(tableContainer, "en_US", "en", "English (US)");
assertLookupRow(tableContainer, "en_PR", "en", "English (pirate)");
assertLookupRow(tableContainer, "sk_SK", "sk", "Slovak");
assertLookupRow(tableContainer, "tr_TR", "tr", "Turkish");
assertLookupRow(tableContainer, "gi_GI", "gi", "Gibberish");
assertLookupRow(tableContainer, "gi_GO", null, "Gobbledygook");
assertLookupRow(tableContainer, "gi_HU", "gi", "Humbug");
assertSteadyResources();
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ResourceManager method completeSchemaAndCapabilities.
private void completeSchemaAndCapabilities(PrismObject<ResourceType> resource, ResourceSchema resourceSchema, boolean fetchedSchema, Map<String, Collection<Object>> capabilityMap, Task task, OperationResult result) throws SchemaException, CommunicationException, ObjectNotFoundException, GenericFrameworkException, ConfigurationException {
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
// Capabilities
// we need to process capabilities first. Schema is one of the connector capabilities.
// We need to determine this capability to select the right connector for schema retrieval.
completeCapabilities(resource, capabilityMap != null, capabilityMap, modifications, result);
if (resourceSchema == null) {
// Try to get existing schema from resource. We do not want to override this if it exists
// (but we still want to refresh the capabilities, that happens below)
resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
}
if (resourceSchema == null || resourceSchema.isEmpty()) {
LOGGER.trace("Fetching resource schema for {}", resource);
resourceSchema = fetchResourceSchema(resource, capabilityMap, task, result);
if (resourceSchema == null) {
LOGGER.warn("No resource schema fetched from {}", resource);
} else if (resourceSchema.isEmpty()) {
LOGGER.warn("Empty resource schema fetched from {}", resource);
} else {
LOGGER.debug("Fetched resource schema for {}: {} definitions", resource, resourceSchema.getDefinitions().size());
fetchedSchema = true;
}
}
if (fetchedSchema) {
adjustSchemaForSimulatedCapabilities(resource, resourceSchema);
ContainerDelta<XmlSchemaType> schemaContainerDelta = createSchemaUpdateDelta(resource, resourceSchema);
modifications.add(schemaContainerDelta);
// We have successfully fetched the resource schema. Therefore the resource must be up.
modifications.add(createResourceAvailabilityStatusDelta(resource, AvailabilityStatusType.UP));
}
if (!modifications.isEmpty()) {
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Completing {}:\n{}", resource, DebugUtil.debugDump(modifications, 1));
}
repositoryService.modifyObject(ResourceType.class, resource.getOid(), modifications, result);
} catch (ObjectAlreadyExistsException ex) {
// This should not happen
throw new SystemException(ex);
}
}
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ResourceManager method modifyResourceAvailabilityStatus.
public void modifyResourceAvailabilityStatus(PrismObject<ResourceType> resource, AvailabilityStatusType status, OperationResult result) {
ResourceType resourceType = resource.asObjectable();
synchronized (resource) {
if (resourceType.getOperationalState() == null || resourceType.getOperationalState().getLastAvailabilityStatus() == null || resourceType.getOperationalState().getLastAvailabilityStatus() != status) {
List<PropertyDelta<?>> modifications = new ArrayList<PropertyDelta<?>>();
PropertyDelta<?> statusDelta = createResourceAvailabilityStatusDelta(resource, status);
modifications.add(statusDelta);
try {
repositoryService.modifyObject(ResourceType.class, resourceType.getOid(), modifications, result);
} catch (SchemaException ex) {
throw new SystemException(ex);
} catch (ObjectAlreadyExistsException ex) {
throw new SystemException(ex);
} catch (ObjectNotFoundException ex) {
throw new SystemException(ex);
}
}
// ugly hack: change object even if it's immutable
boolean immutable = resource.isImmutable();
if (immutable) {
resource.setImmutable(false);
}
if (resourceType.getOperationalState() == null) {
OperationalStateType operationalState = new OperationalStateType();
operationalState.setLastAvailabilityStatus(status);
resourceType.setOperationalState(operationalState);
} else {
resourceType.getOperationalState().setLastAvailabilityStatus(status);
}
if (immutable) {
resource.setImmutable(true);
}
}
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method checkConstraints.
@Override
public ConstraintsCheckingResult checkConstraints(RefinedObjectClassDefinition shadowDefinition, PrismObject<ShadowType> shadowObject, ResourceType resourceType, String shadowOid, ResourceShadowDiscriminator resourceShadowDiscriminator, ConstraintViolationConfirmer constraintViolationConfirmer, Task task, OperationResult parentResult) throws CommunicationException, ObjectAlreadyExistsException, SchemaException, SecurityViolationException, ConfigurationException, ObjectNotFoundException, ExpressionEvaluationException {
OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".checkConstraints");
ConstraintsChecker checker = new ConstraintsChecker();
checker.setCacheRepositoryService(cacheRepositoryService);
checker.setProvisioningService(this);
checker.setPrismContext(prismContext);
checker.setShadowDefinition(shadowDefinition);
checker.setShadowObject(shadowObject);
checker.setResourceType(resourceType);
checker.setShadowOid(shadowOid);
checker.setResourceShadowDiscriminator(resourceShadowDiscriminator);
checker.setConstraintViolationConfirmer(constraintViolationConfirmer);
try {
ConstraintsCheckingResult retval = checker.check(task, result);
result.computeStatus();
return retval;
} catch (CommunicationException | ObjectAlreadyExistsException | SchemaException | SecurityViolationException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
result.recordFatalError(e.getMessage(), e);
throw e;
}
}
Aggregations