use of com.evolveum.midpoint.web.component.prism.ValueStatus in project midpoint by Evolveum.
the class DirectAndIndirectAssignmentPanel method collectResources.
private void collectResources(EvaluatedAssignment<?> evaluatedAssignment, IModel<PrismContainerWrapper<AssignmentType>> parent, Set<AssignmentValueWrapper> assignmentValueWrapperSet, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
DeltaSetTriple<EvaluatedResourceObjectConstruction> evaluatedConstructionsTriple = evaluatedAssignment.getEvaluatedConstructions(task, result);
Collection<EvaluatedResourceObjectConstruction> evaluatedConstructions = evaluatedConstructionsTriple.getNonNegativeValues();
for (EvaluatedResourceObjectConstruction construction : evaluatedConstructions) {
if (!construction.isWeak()) {
PrismContainerDefinition<AssignmentType> assignmentDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class);
AssignmentType assignmentType = assignmentDef.instantiate().createNewValue().asContainerable();
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.setOid(construction.getResource().getOid());
targetRef.setType(ResourceType.COMPLEX_TYPE);
targetRef.setTargetName(new PolyStringType(construction.getResource().getName()));
assignmentType.setTargetRef(targetRef);
ConstructionType constructionType = new ConstructionType();
constructionType.setResourceRef(targetRef);
constructionType.setKind(construction.getKind());
constructionType.setIntent(construction.getIntent());
assignmentType.setConstruction(constructionType);
assignmentType.setDescription(construction.getResource().asObjectable().getDescription());
ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, getPageBase());
assignmentValueWrapper.setDirectAssignment(construction.isDirectlyAssigned());
assignmentValueWrapper.setAssignmentParent(construction.getAssignmentPath());
assignmentValueWrapperSet.add(assignmentValueWrapper);
}
}
}
use of com.evolveum.midpoint.web.component.prism.ValueStatus in project midpoint by Evolveum.
the class DirectAndIndirectAssignmentPanel method collectRoleAndOrgs.
private void collectRoleAndOrgs(EvaluatedAssignment<?> evaluatedAssignment, IModel<PrismContainerWrapper<AssignmentType>> parent, Set<AssignmentValueWrapper> assignmentValueWrapperSet) throws SchemaException {
DeltaSetTriple<? extends EvaluatedAssignmentTarget> targetsTriple = evaluatedAssignment.getRoles();
Collection<? extends EvaluatedAssignmentTarget> targets = targetsTriple.getNonNegativeValues();
for (EvaluatedAssignmentTarget target : targets) {
target.getTarget();
if (ArchetypeType.class.equals(target.getTarget().getCompileTimeClass())) {
continue;
}
if (target.appliesToFocusWithAnyRelation(getPageBase().getRelationRegistry())) {
AssignmentType assignmentType = target.getAssignment().clone();
assignmentType.setDescription(target.getTarget().asObjectable().getDescription());
assignmentType.getTargetRef().setOid(target.getTarget().getOid());
assignmentType.getTargetRef().setTargetName(new PolyStringType(target.getTarget().getName()));
assignmentType.getTargetRef().setType(target.getTarget().getComplexTypeDefinition().getTypeName());
ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, getPageBase());
assignmentValueWrapper.setDirectAssignment(target.isDirectlyAssigned());
assignmentValueWrapper.setAssignmentParent(target.getAssignmentPath());
assignmentValueWrapperSet.add(assignmentValueWrapper);
}
}
}
use of com.evolveum.midpoint.web.component.prism.ValueStatus in project midpoint by Evolveum.
the class AbstractGuiIntegrationTest method getServiceLocator.
protected ModelServiceLocator getServiceLocator(final Task pageTask) {
return new ModelServiceLocator() {
@Override
public ModelService getModelService() {
return modelService;
}
@Override
public ModelInteractionService getModelInteractionService() {
return modelInteractionService;
}
@Override
public DashboardService getDashboardService() {
return dashboardService;
}
@Override
public Task createSimpleTask(String operationName) {
MidPointPrincipal user = AuthUtil.getPrincipalUser();
if (user == null) {
throw new IllegalStateException("No authenticated user");
}
return WebModelServiceUtils.createSimpleTask(operationName, SchemaConstants.CHANNEL_USER_URI, user.getFocus().asPrismObject(), taskManager);
}
@Override
public PrismContext getPrismContext() {
return prismContext;
}
@Override
public SecurityEnforcer getSecurityEnforcer() {
return securityEnforcer;
}
@Override
public SecurityContextManager getSecurityContextManager() {
return securityContextManager;
}
@NotNull
@Override
public CompiledGuiProfile getCompiledGuiProfile() {
Task task = createSimpleTask("getCompiledGuiProfile");
try {
return getModelInteractionService().getCompiledGuiProfile(task, task.getResult());
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new SystemException(e.getMessage(), e);
}
}
@Override
public Task getPageTask() {
return pageTask;
}
@Override
public ExpressionFactory getExpressionFactory() {
return expressionFactory;
}
@Override
public LocalizationService getLocalizationService() {
return localizationService;
}
@Override
public Locale getLocale() {
return Locale.US;
}
@Override
public GuiComponentRegistry getRegistry() {
return registry;
}
@Override
public <O extends ObjectType> PrismObjectWrapperFactory<O> findObjectWrapperFactory(PrismObjectDefinition<O> objectDef) {
return registry.getObjectWrapperFactory(objectDef);
}
@Override
public <I extends Item, IW extends ItemWrapper> IW createItemWrapper(I item, ItemStatus status, WrapperContext ctx) throws SchemaException {
ItemWrapperFactory<IW, ?, ?> factory = registry.findWrapperFactory(item.getDefinition(), null);
ctx.setCreateIfEmpty(true);
return factory.createWrapper(null, item, status, ctx);
}
@Override
public <IW extends ItemWrapper, VW extends PrismValueWrapper, PV extends PrismValue> VW createValueWrapper(IW parentWrapper, PV newValue, ValueStatus status, WrapperContext context) throws SchemaException {
ItemWrapperFactory<IW, VW, PV> factory = registry.findWrapperFactory(parentWrapper, null);
return factory.createValueWrapper(parentWrapper, newValue, status, context);
}
@Override
public MidpointFormValidatorRegistry getFormValidatorRegistry() {
return null;
}
@Override
public AdminGuiConfigurationMergeManager getAdminGuiConfigurationMergeManager() {
return null;
}
@Override
public CorrelationService getCorrelationService() {
return null;
}
};
}
use of com.evolveum.midpoint.web.component.prism.ValueStatus in project midpoint by Evolveum.
the class TaskBasicTabPanel method initLayout.
private void initLayout() {
ItemPanelSettings settings = new ItemPanelSettingsBuilder().editabilityHandler(wrapper -> getTask().getHandlerUri() == null).build();
TaskHandlerSelectorPanel handlerSelectorPanel = new TaskHandlerSelectorPanel(ID_HANDLER, PrismPropertyWrapperModel.fromContainerWrapper(getModel(), TaskType.F_HANDLER_URI), settings) {
@Override
protected void onUpdatePerformed(AjaxRequestTarget target) {
String newHandlerUri = getTask().getHandlerUri();
if (StringUtils.isBlank(newHandlerUri) || !newHandlerUri.startsWith("http://")) {
LOGGER.trace("Nothing to do, handler still not set");
return;
}
TaskHandler taskHandler = getPageBase().getTaskManager().getHandler(newHandlerUri);
if (taskHandler == null) {
LOGGER.trace("Nothing to do, cannot find TaskHandler for {}", newHandlerUri);
return;
}
if (!WebComponentUtil.hasAnyArchetypeAssignment(getTask())) {
String archetypeOid = taskHandler.getArchetypeOid(newHandlerUri);
WebComponentUtil.addNewArchetype(TaskBasicTabPanel.this.getModelObject(), archetypeOid, target, getPageBase());
}
PrismObjectWrapperFactory<TaskType> wrapperFactory = TaskBasicTabPanel.this.getPageBase().findObjectWrapperFactory(getTask().asPrismObject().getDefinition());
Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_WRAPPER);
OperationResult result = task.getResult();
WrapperContext ctx = new WrapperContext(task, result);
ctx.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(getTask().asPrismObject()));
try {
wrapperFactory.updateWrapper(TaskBasicTabPanel.this.getModelObject(), ctx);
// TODO ugly hack: after updateWrapper method is called, both previously set items (handlerUri and assignments)
// are marked as NOT_CHANGED with the same value. We need to find a way how to force the ValueStatus
// or change the mechanism for computing deltas. Probably only the first will work
PrismPropertyWrapper<String> handlerWrapper = TaskBasicTabPanel.this.getModelObject().findProperty(ItemPath.create(TaskType.F_HANDLER_URI));
handlerWrapper.getValue().setStatus(ValueStatus.ADDED);
PrismContainerWrapper<AssignmentType> assignmentWrapper = TaskBasicTabPanel.this.getModelObject().findContainer(ItemPath.create(TaskType.F_ASSIGNMENT));
for (PrismContainerValueWrapper<AssignmentType> assignmentWrapperValue : assignmentWrapper.getValues()) {
if (WebComponentUtil.isArchetypeAssignment(assignmentWrapperValue.getRealValue())) {
assignmentWrapperValue.setStatus(ValueStatus.ADDED);
}
}
} catch (SchemaException | IllegalArgumentException e) {
LOGGER.error("Unexpected problem occurs during updating wrapper. Reason: {}", e.getMessage(), e);
}
updateHandlerPerformed(target);
}
};
handlerSelectorPanel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return satisfyArchetypeAssignment();
}
});
add(handlerSelectorPanel);
ItemVisibilityHandler visibilityHandler = wrapper -> getBasicTabVisibility(wrapper.getPath());
ItemEditabilityHandler editabilityHandler = wrapper -> getBasicTabEditability(wrapper.getPath());
try {
ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder().visibilityHandler(visibilityHandler).editabilityHandler(editabilityHandler).mandatoryHandler(getItemMandatoryHandler());
Panel panel = getPageBase().initItemPanel(ID_MAIN_PANEL, TaskType.COMPLEX_TYPE, getModel(), builder.build());
add(panel);
} catch (SchemaException e) {
LOGGER.error("Cannot create task basic panel: {}", e.getMessage(), e);
// TODO opertion result? localization?
getSession().error("Cannot create task basic panel");
throw new RestartResponseException(PageTasks.class);
}
}
use of com.evolveum.midpoint.web.component.prism.ValueStatus in project midpoint by Evolveum.
the class PageAdminFocus method showAllAssignmentsPerformed.
public List<AssignmentValueWrapper> showAllAssignmentsPerformed(IModel<PrismContainerWrapper<AssignmentType>> parent) {
LOGGER.debug("Recompute user assignments");
Task task = createSimpleTask(OPERATION_RECOMPUTE_ASSIGNMENTS);
OperationResult result = new OperationResult(OPERATION_RECOMPUTE_ASSIGNMENTS);
ObjectDelta<F> delta;
Set<AssignmentValueWrapper> assignmentValueWrapperSet = new TreeSet<>();
try {
reviveModels();
PrismObjectWrapper<F> focusWrapper = getObjectWrapper();
delta = focusWrapper.getObjectDelta();
switch(focusWrapper.getStatus()) {
case ADDED:
PrismObject<F> focus = delta.getObjectToAdd();
prepareObjectForAdd(focus);
getPrismContext().adopt(focus, getCompileTimeClass());
LOGGER.trace("Delta before add focus:\n{}", delta.debugDumpLazily(3));
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
} else {
result.recordSuccess();
}
break;
case NOT_CHANGED:
prepareObjectDeltaForModify(delta);
LOGGER.trace("Delta before modify user:\n{}", delta.debugDumpLazily(3));
List<ObjectDelta<? extends ObjectType>> accountDeltas = getShadowModifyDeltas(result);
if (!delta.isEmpty()) {
delta.revive(getPrismContext());
}
for (ObjectDelta accDelta : accountDeltas) {
if (!accDelta.isEmpty()) {
accDelta.revive(getPrismContext());
}
}
break;
default:
error(getString("pageAdminFocus.message.unsupportedState", focusWrapper.getStatus()));
}
ModelContext<UserType> modelContext;
try {
ModelExecuteOptions options = executeOptions().evaluateAllAssignmentRelationsOnRecompute();
modelContext = getModelInteractionService().previewChanges(Collections.singleton(delta), options, task, result);
} catch (NoFocusNameSchemaException e) {
info(getString("pageAdminFocus.message.noUserName"));
return null;
}
Collection<? extends EvaluatedAssignment<?>> evaluatedAssignments = modelContext.getNonNegativeEvaluatedAssignments();
if (evaluatedAssignments.isEmpty()) {
info(getString("pageAdminFocus.message.noAssignmentsAvailable"));
return null;
}
for (EvaluatedAssignment<?> evaluatedAssignment : evaluatedAssignments) {
if (!evaluatedAssignment.isValid()) {
continue;
}
// roles and orgs
DeltaSetTriple<? extends EvaluatedAssignmentTarget> targetsTriple = evaluatedAssignment.getRoles();
Collection<? extends EvaluatedAssignmentTarget> targets = targetsTriple.getNonNegativeValues();
for (EvaluatedAssignmentTarget target : targets) {
target.getTarget();
if (ArchetypeType.class.equals(target.getTarget().getCompileTimeClass())) {
continue;
}
if (target.appliesToFocusWithAnyRelation(getRelationRegistry())) {
AssignmentType assignmentType = target.getAssignment().clone();
assignmentType.setDescription(target.getTarget().asObjectable().getDescription());
assignmentType.getTargetRef().setTargetName(new PolyStringType(target.getTarget().getName()));
assignmentType.getTargetRef().setType(target.getTarget().getComplexTypeDefinition().getTypeName());
ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, this);
assignmentValueWrapper.setDirectAssignment(target.isDirectlyAssigned());
assignmentValueWrapper.setAssignmentParent(target.getAssignmentPath());
assignmentValueWrapperSet.add(assignmentValueWrapper);
}
}
// all resources
DeltaSetTriple<EvaluatedResourceObjectConstruction> evaluatedConstructionsTriple = evaluatedAssignment.getEvaluatedConstructions(task, result);
Collection<EvaluatedResourceObjectConstruction> evaluatedConstructions = evaluatedConstructionsTriple.getNonNegativeValues();
for (EvaluatedResourceObjectConstruction construction : evaluatedConstructions) {
if (!construction.isWeak()) {
PrismContainerDefinition<AssignmentType> assignmentDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class);
AssignmentType assignmentType = assignmentDef.instantiate().createNewValue().asContainerable();
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.setOid(construction.getResource().getOid());
targetRef.setType(ResourceType.COMPLEX_TYPE);
targetRef.setTargetName(new PolyStringType(construction.getResource().getName()));
assignmentType.setTargetRef(targetRef);
ConstructionType constructionType = new ConstructionType();
constructionType.setResourceRef(targetRef);
constructionType.setKind(construction.getKind());
constructionType.setIntent(construction.getIntent());
assignmentType.setConstruction(constructionType);
assignmentType.setDescription(construction.getResource().asObjectable().getDescription());
ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, this);
assignmentValueWrapper.setDirectAssignment(construction.isDirectlyAssigned());
assignmentValueWrapper.setAssignmentParent(construction.getAssignmentPath());
assignmentValueWrapperSet.add(assignmentValueWrapper);
}
}
}
return new ArrayList<>(assignmentValueWrapperSet);
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Could not create assignments preview.", e);
error("Could not create assignments preview. Reason: " + e);
}
return null;
}
Aggregations