use of org.apache.syncope.client.console.commons.status.StatusBean in project syncope by apache.
the class ChangePasswordModal method onSubmit.
@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
final UserTO inner = wrapper.getInnerObject();
try {
if (StringUtils.isBlank(inner.getPassword()) || statusModel.getObject().isEmpty()) {
SyncopeConsoleSession.get().error(getString(Constants.OPERATION_ERROR));
} else {
final List<String> resources = new ArrayList<>();
boolean isOnSyncope = false;
for (StatusBean sb : statusModel.getObject()) {
if (sb.getResource().equals(Constants.SYNCOPE)) {
isOnSyncope = true;
} else {
resources.add(sb.getResource());
}
}
final UserPatch patch = new UserPatch();
patch.setKey(inner.getKey());
PasswordPatch passwordPatch = new PasswordPatch.Builder().value(inner.getPassword()).onSyncope(isOnSyncope).resources(resources).build();
patch.setPassword(passwordPatch);
userRestClient.update(inner.getETagValue(), patch);
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
modal.show(false);
modal.close(target);
}
} catch (Exception e) {
LOG.error("While updating password for user {}", inner, e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
}
super.onSubmit(target, form);
}
use of org.apache.syncope.client.console.commons.status.StatusBean in project syncope by apache.
the class StatusPanel method init.
private void init(final AnyTO any, final IModel<List<StatusBean>> model, final List<Pair<ConnObjectTO, ConnObjectWrapper>> connObjects, final PageReference pageRef, final boolean enableConnObjectLink) {
final List<StatusBean> statusBeans = new ArrayList<>(connObjects.size() + 1);
initialStatusBeanMap = new LinkedHashMap<>(connObjects.size() + 1);
final StatusBean syncope = new StatusBean(any, Constants.SYNCOPE);
if (any instanceof UserTO) {
syncope.setConnObjectLink(((UserTO) any).getUsername());
Status syncopeStatus = Status.UNDEFINED;
if (((UserTO) any).getStatus() != null) {
try {
syncopeStatus = Status.valueOf(((UserTO) any).getStatus().toUpperCase());
} catch (IllegalArgumentException e) {
LOG.warn("Unexpected status found: {}", ((UserTO) any).getStatus(), e);
}
}
syncope.setStatus(syncopeStatus);
} else if (any instanceof GroupTO) {
syncope.setConnObjectLink(((GroupTO) any).getName());
syncope.setStatus(Status.ACTIVE);
}
statusBeans.add(syncope);
initialStatusBeanMap.put(syncope.getResource(), syncope);
connObjects.forEach(pair -> {
ConnObjectWrapper entry = pair.getRight();
final StatusBean statusBean = statusUtils.getStatusBean(entry.getAny(), entry.getResourceName(), entry.getConnObjectTO(), any instanceof GroupTO);
initialStatusBeanMap.put(entry.getResourceName(), statusBean);
statusBeans.add(statusBean);
});
final MultilevelPanel mlp = new MultilevelPanel("resources");
add(mlp);
ListViewPanel.Builder<StatusBean> builder = new ListViewPanel.Builder<StatusBean>(StatusBean.class, pageRef) {
private static final long serialVersionUID = -6809736686861678498L;
@Override
protected Component getValueComponent(final String key, final StatusBean bean) {
if ("status".equalsIgnoreCase(key)) {
return StatusUtils.getStatusImagePanel("field", bean.getStatus());
} else {
return super.getValueComponent(key, bean);
}
}
};
builder.setModel(model);
builder.setItems(statusBeans);
builder.includes("resource", "connObjectLink", "status");
builder.withChecks(ListViewPanel.CheckAvailability.NONE);
builder.setReuseItem(false);
final ActionLink<StatusBean> connObjectLink = new ActionLink<StatusBean>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
protected boolean statusCondition(final StatusBean bean) {
final Pair<ConnObjectTO, ConnObjectTO> pair = getConnObjectTO(bean.getKey(), bean.getResource(), connObjects);
return pair != null && pair.getRight() != null;
}
@Override
public void onClick(final AjaxRequestTarget target, final StatusBean bean) {
mlp.next(bean.getResource(), new RemoteAnyPanel(bean, connObjects), target);
}
};
if (!enableConnObjectLink) {
connObjectLink.disable();
}
builder.addAction(connObjectLink, ActionLink.ActionType.VIEW, StandardEntitlement.RESOURCE_GET_CONNOBJECT);
listViewPanel = ListViewPanel.class.cast(builder.build(MultilevelPanel.FIRST_LEVEL_ID));
mlp.setFirstLevel(listViewPanel);
}
Aggregations