use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.
the class AddCapabilityDialog method initLayout.
private void initLayout(WebMarkupContainer container) {
List<IColumn<CapabilityDto<CapabilityType>, String>> columns = initColumns();
TablePanel<CapabilityDto<CapabilityType>> table = new TablePanel<>(ID_TABLE, createProvider(), columns);
table.setOutputMarkupId(true);
table.setShowPaging(false);
container.add(table);
AjaxButton cancelButton = new AjaxButton(ID_CANCEL, createStringResource("addCapabilityDialog.button.cancel")) {
@Override
public void onClick(AjaxRequestTarget ajaxRequestTarget) {
cancelPerformed(ajaxRequestTarget);
}
};
container.add(cancelButton);
AjaxButton addButton = new AjaxButton(ID_ADD, createStringResource("addCapabilityDialog.button.Add")) {
@Override
public void onClick(AjaxRequestTarget target) {
addPerformed(target);
}
};
container.add(addButton);
}
use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.
the class CapabilityStep method editCapabilityPerformed.
@SuppressWarnings("unchecked")
private void editCapabilityPerformed(final AjaxRequestTarget target, CapabilityDto<? extends CapabilityType> capability) {
dtoModel.getObject().setSelected(capability);
WebMarkupContainer config = getConfigContainer();
WebMarkupContainer newConfig;
CapabilityType capType = capability.getCapability();
if (capType instanceof ActivationCapabilityType) {
newConfig = new CapabilityActivationPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ActivationCapabilityType>) capability), parentPage) {
@Override
public IModel<List<QName>> createAttributeChoiceModel(final IChoiceRenderer<QName> renderer) {
LoadableModel<List<QName>> attributeChoiceModel = new LoadableModel<List<QName>>(false) {
@Override
protected List<QName> load() {
List<QName> choices = new ArrayList<>();
PrismObject<ResourceType> resourcePrism = resourceModel.getObject();
try {
ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resourcePrism, getPageBase().getPrismContext());
if (schema != null) {
ObjectClassComplexTypeDefinition def = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
for (ResourceAttributeDefinition attribute : def.getAttributeDefinitions()) {
choices.add(attribute.getName());
}
}
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource schema attributes.", e);
getPageBase().error("Couldn't load resource schema attributes" + e);
}
Collections.sort(choices, new Comparator<QName>() {
@Override
public int compare(QName o1, QName o2) {
String s1 = (String) renderer.getDisplayValue(o1);
String s2 = (String) renderer.getDisplayValue(o2);
return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
}
});
return choices;
}
};
parentPage.registerDependentModel(attributeChoiceModel);
return attributeChoiceModel;
}
};
} else if (capType instanceof ScriptCapabilityType) {
newConfig = new CapabilityScriptPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ScriptCapabilityType>) capability), getTable(), parentPage);
} else if (capType instanceof CredentialsCapabilityType) {
newConfig = new CapabilityCredentialsPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CredentialsCapabilityType>) capability), getTable(), parentPage);
} else {
newConfig = new CapabilityValuePanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CapabilityType>) capability), getTable(), parentPage);
}
// TODO other specific capabilities (paged, count, ...)
newConfig.setOutputMarkupId(true);
config.replaceWith(newConfig);
target.add(newConfig);
target.add(getTable());
}
use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.
the class CapabilityStep method savePerformed.
private void savePerformed() {
Task task = getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES);
OperationResult result = task.getResult();
ModelService modelService = getPageBase().getModelService();
boolean saved = false;
try {
PrismObject<ResourceType> oldResource;
final PrismObject<ResourceType> resourceObject = resourceModel.getObject();
ResourceType resource = resourceObject.asObjectable();
List<Object> unsupportedCapabilities = new ArrayList<>();
if (resource.getCapabilities().getConfigured() != null) {
for (Object o : resource.getCapabilities().getConfigured().getAny()) {
CapabilityType capabilityType = CapabilityUtil.asCapabilityType(o);
if (!Capability.supports(capabilityType.getClass())) {
unsupportedCapabilities.add(o);
}
}
}
// AnyArrayList that is used to implement getAny() is really strange (e.g. doesn't support iterator.remove();
// and its support for clear() is questionable) -- so let's recreate it altogether
resource.getCapabilities().setConfigured(new CapabilityCollectionType());
resource.getCapabilities().getConfigured().getAny().addAll(unsupportedCapabilities);
ObjectFactory capabilityFactory = new ObjectFactory();
for (CapabilityDto dto : dtoModel.getObject().getCapabilities()) {
JAXBElement<? extends CapabilityType> jaxbCapability = createJAXBCapability(dto.getCapability(), capabilityFactory);
if (jaxbCapability != null) {
resource.getCapabilities().getConfigured().getAny().add(jaxbCapability);
}
}
oldResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
if (oldResource != null) {
ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, resourceObject);
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
@SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES), result);
parentPage.resetModels();
saved = true;
}
}
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save capabilities", e);
result.recordFatalError("Couldn't save capabilities", e);
} finally {
result.computeStatusIfUnknown();
setResult(result);
}
if (parentPage.showSaveResultInPage(saved, result)) {
getPageBase().showResult(result);
}
}
use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.
the class CapabilityStep method getCapabilitiesFromResource.
private List<CapabilityDto<CapabilityType>> getCapabilitiesFromResource(ResourceType resource) {
List<CapabilityDto<CapabilityType>> capabilityList = new ArrayList<>();
try {
Collection<Class<? extends CapabilityType>> nativeClasses = ResourceTypeUtil.getNativeCapabilityClasses(resource);
List<Object> objects = ResourceTypeUtil.getAllCapabilities(resource);
for (Object capabilityObject : objects) {
CapabilityType capability = CapabilityUtil.asCapabilityType(capabilityObject);
if (Capability.supports(capability.getClass())) {
capability = fillDefaults(capability);
capabilityList.add(new CapabilityDto<>(capability, nativeClasses.contains(capability.getClass())));
} else {
LOGGER.warn("Capability unsupported by the Resource Wizard: {}", capability);
}
}
} catch (SchemaException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load capabilities", e);
getPageBase().error(getString("CapabilityStep.message.cantLoadCaps") + e);
}
return capabilityList;
}
use of com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto in project midpoint by Evolveum.
the class CapabilityStep method initLayout.
protected void initLayout() {
final ListDataProvider<CapabilityDto<CapabilityType>> capabilityProvider = new ListDataProvider<>(this, new PropertyModel<List<CapabilityDto<CapabilityType>>>(dtoModel, CapabilityStepDto.F_CAPABILITIES));
WebMarkupContainer tableBody = new WebMarkupContainer(ID_CAPABILITY_TABLE);
tableBody.setOutputMarkupId(true);
add(tableBody);
WebMarkupContainer configBody = new WebMarkupContainer(ID_CAPABILITY_CONFIG);
configBody.setOutputMarkupId(true);
add(configBody);
DataView<CapabilityDto<CapabilityType>> capabilityDataView = new DataView<CapabilityDto<CapabilityType>>(ID_CAPABILITY_ROW, capabilityProvider) {
@Override
protected void populateItem(final Item<CapabilityDto<CapabilityType>> capabilityRow) {
final CapabilityDto<CapabilityType> dto = capabilityRow.getModelObject();
AjaxLink name = new AjaxLink(ID_CAPABILITY_LINK) {
@Override
public void onClick(AjaxRequestTarget target) {
editCapabilityPerformed(target, dto);
}
};
Label label = new Label(ID_CAPABILITY_NAME, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
String rv = dto.getDisplayName();
if (Boolean.FALSE.equals(dto.getCapability().isEnabled())) {
rv += " " + getString("CapabilityStep.disabled");
}
return rv;
}
});
name.add(label);
capabilityRow.add(name);
Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
if (dto.getTooltipKey() != null) {
tooltipLabel.add(new AttributeAppender("data-original-title", getString(dto.getTooltipKey())));
tooltipLabel.add(new InfoTooltipBehavior());
} else {
tooltipLabel.setVisible(false);
}
tooltipLabel.setOutputMarkupId(true);
tooltipLabel.setOutputMarkupPlaceholderTag(true);
name.add(tooltipLabel);
AjaxLink deleteLink = new AjaxLink(ID_CAPABILITY_DELETE) {
@Override
public void onClick(AjaxRequestTarget target) {
deleteCapabilityPerformed(target, dto);
}
};
deleteLink.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return !dto.isAmongNativeCapabilities() && !parentPage.isReadOnly();
}
});
name.add(deleteLink);
capabilityRow.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<Object>() {
@Override
public Object getObject() {
return isSelected(capabilityRow.getModelObject()) ? "success" : null;
}
}));
}
};
tableBody.add(capabilityDataView);
AjaxLink addLink = new AjaxLink(ID_CAPABILITY_ADD) {
@Override
public void onClick(AjaxRequestTarget target) {
addCapabilityPerformed(target);
}
};
parentPage.addEditingVisibleBehavior(addLink);
add(addLink);
ModalWindow dialog = new AddCapabilityDialog(DIALOG_SELECT_CAPABILITY, dtoModel) {
@Override
protected void addPerformed(AjaxRequestTarget target) {
addCapabilitiesPerformed(target, getSelectedData());
}
};
add(dialog);
}
Aggregations