private void fixProvisioningTypeInDelta(ObjectDelta delta, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { if (delta != null && delta.getObjectTypeClass() != null && (ShadowType.class.isAssignableFrom(delta.getObjectTypeClass()) || ResourceType.class.isAssignableFrom(delta.getObjectTypeClass()))) { // TODO exception can be thrown here (MID-4391) e.g. if resource does not exist any more; consider what to do // Currently we are on the safe side by making whole conversion fail getProvisioningService().applyDefinition(delta, task, result); } }
@Override public <T extends ObjectType> void applyDefinition(T object) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { if (object instanceof ShadowType || object instanceof ResourceType) { provisioningService.applyDefinition(object.asPrismObject(), getCurrentTask(), getCurrentResult()); } }
protected void fixProvisioningTypeInDelta(ObjectDelta<O> delta, Objectable object, Task task, OperationResult result) { if (delta != null && delta.getObjectTypeClass() != null && (ShadowType.class.isAssignableFrom(delta.getObjectTypeClass()) || ResourceType.class.isAssignableFrom(delta.getObjectTypeClass()))) { try { lensContext.getProvisioningService().applyDefinition(delta, object, task, result); } catch (Exception e) { LOGGER.warn("Error applying provisioning definitions to delta {}: {}", delta, e.getMessage()); // In case of error just go on. Maybe we do not have correct definition here. But at least we can // display the GUI pages and maybe we can also salvage the operation. result.recordWarning(e); } } }
private void fixProvisioningTypeInObject(PrismObject<O> object, Task task, OperationResult result) { if (object != null && object.getCompileTimeClass() != null && (ShadowType.class.isAssignableFrom(object.getCompileTimeClass()) || ResourceType.class.isAssignableFrom(object.getCompileTimeClass()))) { try { lensContext.getProvisioningService().applyDefinition(object, task, result); } catch (Exception e) { LOGGER.warn("Error applying provisioning definitions to object {}: {}", object, e.getMessage()); // In case of error just go on. Maybe we do not have correct definition here. But at least we can // display the GUI pages and maybe we can also salvage the operation. result.recordWarning(e); } } }
protected LensProjectionContext fillContextWithAccount(LensContext<UserType> context, String accountOid, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { PrismObject<ShadowType> account = repositoryService.getObject(ShadowType.class, accountOid, null, result); provisioningService.applyDefinition(account, task, result); return fillContextWithAccount(context, account, task, result); }
protected LensProjectionContext fillContextWithAccountFromFile(LensContext<UserType> context, File file, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, IOException, ExpressionEvaluationException { PrismObject<ShadowType> account = PrismTestUtil.parseObject(file); provisioningService.applyDefinition(account, task, result); return fillContextWithAccount(context, account, task, result); }
public <F extends ObjectType> LensContext<F> createRecomputeProjectionContext( PrismObject<ShadowType> shadow, ModelExecuteOptions options, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { provisioningService.applyDefinition(shadow, task, result); LensContext<F> syncContext = new LensContext<>(null, prismContext, provisioningService); LensProjectionContext projectionContext = syncContext.createProjectionContext(); projectionContext.setLoadedObject(shadow); projectionContext.setOid(shadow.getOid()); projectionContext.setDoReconciliation(ModelExecuteOptions.isReconcile(options)); syncContext.setChannel(SchemaConstants.CHANGE_CHANNEL_RECOMPUTE_URI); return syncContext; }
public <O extends ObjectType> void resolve(PrismObject<O> object, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException { /*if (object.getDefinition() == null) */{ if (object == null) { return; } Class<O> clazz = object.getCompileTimeClass(); if (clazz == null) { warn(result, "Compile time class for " + toShortString(object) + " is not known"); } else { PrismObjectDefinition<O> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(clazz); if (def != null) { if (ResourceType.class.isAssignableFrom(clazz) || ShadowType.class.isAssignableFrom(clazz)) { try { provisioningService.applyDefinition(object, task, result); } catch (ObjectNotFoundException|CommunicationException|ConfigurationException e) { LoggingUtils.logUnexpectedException(LOGGER, "Couldn't apply definition on {} -- continuing with no definition", e, ObjectTypeUtil.toShortString(object)); } } else { object.applyDefinition(def); } } else { warn(result, "Definition for " + toShortString(object) + " couldn't be found"); } } } }
private void applyDefinitions(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { for(ObjectDelta<? extends ObjectType> delta: deltas) { Class<? extends ObjectType> type = delta.getObjectTypeClass(); if (delta.hasCompleteDefinition()) { continue; } if (type == ResourceType.class || ShadowType.class.isAssignableFrom(type)) { try { provisioning.applyDefinition(delta, task, result); } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) { if (ModelExecuteOptions.isRaw(options)) { ModelImplUtils.recordPartialError(result, e); // just go on, this is raw, we need to continue even without complete schema } else { ModelImplUtils.recordFatalError(result, e); throw e; } } } else { PrismObjectDefinition objDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(delta.getObjectTypeClass()); if (objDef == null) { throw new SchemaException("No definition for delta object type class: " + delta.getObjectTypeClass()); } boolean tolerateNoDefinition = ModelExecuteOptions.isRaw(options); delta.applyDefinitionIfPresent(objDef, tolerateNoDefinition); } } }
@Test public void test105ApplyDefinitionModifyDelta() throws Exception { final String TEST_NAME = "test105ApplyDefinitionModifyDelta"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ObjectModificationType changeAddRoleCaptain = PrismTestUtil.parseAtomicValue(MODIFY_ACCOUNT_FILE, ObjectModificationType.COMPLEX_TYPE); ObjectDelta<ShadowType> accountDelta = DeltaConvertor.createObjectDelta(changeAddRoleCaptain, ShadowType.class, prismContext); // WHEN provisioningService.applyDefinition(accountDelta, task, result); // THEN assertSuccess(result); accountDelta.checkConsistence(true, true, true); assertSteadyResource(); }
private LensProjectionContext fillContextWithDummyElaineAccount( LensContext<UserType> context, String dummyName, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, IOException, ExpressionEvaluationException { String resourceOid = getDummyOid(dummyName); String accountOid = getDummuAccountOid(dummyName,"e"); PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_ELAINE_TEMPLATE_FILE); ShadowType accountType = account.asObjectable(); accountType.setOid(accountOid); accountType.getResourceRef().setOid(resourceOid); provisioningService.applyDefinition(account, task, result); return fillContextWithAccount(context, account, task, result); }
private void reactShadowGone(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, Task task, OperationResult result) { try { provisioningService.applyDefinition(shadow, task, result); ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription(); change.setSourceChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_RECON)); change.setResource(resource); ObjectDelta<ShadowType> shadowDelta = shadow.getPrismContext().deltaFactory().object() .createDeleteDelta(ShadowType.class, shadow.getOid() ); change.setObjectDelta(shadowDelta); // Need to also set current shadow. This will get reflected in "old" object in lens context change.setCurrentShadow(shadow); ModelImplUtils.clearRequestee(task); changeNotificationDispatcher.notifyChange(change, task, result); } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) { processShadowReconError(e, shadow, result); } }
@Test public void test040ApplyDefinitionShadow() throws Exception { final String TEST_NAME = "test040ApplyDefinitionShadow"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ShadowType> account = PrismTestUtil.parseObject(getAccountWillFile()); // WHEN provisioningService.applyDefinition(account, task, result); // THEN result.computeStatus(); display("applyDefinition result", result); TestUtil.assertSuccess(result); account.checkConsistence(true, true); ShadowUtil.checkConsistence(account, TEST_NAME); TestUtil.assertSuccess("applyDefinition(account) result", result); assertSteadyResource(); }
@Test public void test041ApplyDefinitionAddShadowDelta() throws Exception { final String TEST_NAME = "test041ApplyDefinitionAddShadowDelta"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ShadowType> account = PrismTestUtil.parseObject(getAccountWillFile()); ObjectDelta<ShadowType> delta = account.createAddDelta(); // WHEN provisioningService.applyDefinition(delta, task, result); // THEN result.computeStatus(); display("applyDefinition result", result); TestUtil.assertSuccess(result); delta.checkConsistence(true, true, true); TestUtil.assertSuccess("applyDefinition(add delta) result", result); assertSteadyResource(); }
@Override public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException { for (PipelineItem item: input.getData()) { PrismValue value = item.getValue(); OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult); context.checkTaskStop(); if (value instanceof PrismObjectValue) { @SuppressWarnings({"unchecked", "raw"}) PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject(); ObjectType objectBean = prismObject.asObjectable(); if (objectBean instanceof ShadowType || objectBean instanceof ResourceType) { try { provisioningService.applyDefinition(prismObject, context.getTask(), result); result.computeStatus(); } catch (Throwable ex) { result.recordFatalError("Couldn't reencrypt object", ex); Throwable exception = processActionException(ex, NAME, value, context); context.println("Couldn't apply definition to " + prismObject.toString() + exceptionSuffix(exception)); } } } else { //noinspection ThrowableNotThrown processActionException(new ScriptExecutionException("Item is not a PrismObject"), NAME, value, context); } operationsHelper.trimAndCloneResult(result, globalResult, context); } return input; } }
@Test public void test202SearchObjectsCompexFilter() throws Exception { final String TEST_NAME = "test202SearchObjectsCompexFilter"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); QueryType queryType = PrismTestUtil.parseAtomicValue(QUERY_COMPLEX_FILTER_FILE, QueryType.COMPLEX_TYPE); ObjectQuery query = getQueryConverter().createObjectQuery(ShadowType.class, queryType); provisioningService.applyDefinition(ShadowType.class, query, task, result); rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT); rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT); // WHEN displayWhen(TEST_NAME); List<PrismObject<ShadowType>> objListType = provisioningService.searchObjects(ShadowType.class, query, null, task, result); // THEN displayThen(TEST_NAME); result.computeStatus(); TestUtil.assertSuccess(result); for (PrismObject<ShadowType> objType : objListType) { assertNotNull("Null search result", objType); display("found object", objType); } assertEquals("Unexpected number of objects found", 1, objListType.size()); assertConnectorOperationIncrement(1, 3); assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0); }
QueryType.COMPLEX_TYPE); ObjectQuery query = getQueryConverter().createObjectQuery(ShadowType.class, queryType); provisioningService.applyDefinition(ShadowType.class, query, task, result);
@Test public void test042ApplyDefinitionResource() throws Exception { final String TEST_NAME = "test042ApplyDefinitionResource"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ResourceType> resource = PrismTestUtil.parseObject(getResourceDummyFile()); // Transplant connector OID. The freshly-parsed resource does have only the fake one. resource.asObjectable().getConnectorRef().setOid(this.resourceType.getConnectorRef().getOid()); // Make sure this object has a different OID than the one already loaded. This avoids caching // and other side-effects resource.setOid(RESOURCE_DUMMY_NONEXISTENT_OID); // WHEN provisioningService.applyDefinition(resource, task, result); // THEN result.computeStatus(); display("applyDefinition result", result); TestUtil.assertSuccess(result); resource.checkConsistence(true, true); TestUtil.assertSuccess("applyDefinition(resource) result", result); assertSteadyResource(); }
provisioningService.applyDefinition(delta, task, result); display("ObjectDelta", delta); delta.checkConsistence();
@Test public void test043ApplyDefinitionAddResourceDelta() throws Exception { final String TEST_NAME = "test043ApplyDefinitionAddResourceDelta"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ResourceType> resource = PrismTestUtil.parseObject(getResourceDummyFile()); // Transplant connector OID. The freshly-parsed resource does have only the fake one. resource.asObjectable().getConnectorRef().setOid(this.resourceType.getConnectorRef().getOid()); ObjectDelta<ResourceType> delta = resource.createAddDelta(); // Make sure this object has a different OID than the one already loaded. This avoids caching // and other side-effects resource.setOid(RESOURCE_DUMMY_NONEXISTENT_OID); // WHEN provisioningService.applyDefinition(delta, task, result); // THEN result.computeStatus(); display("applyDefinition result", result); TestUtil.assertSuccess(result); delta.checkConsistence(true, true, true); TestUtil.assertSuccess("applyDefinition(add delta) result", result); assertSteadyResource(); }