use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class DynRealmITCase method misc.
@Test
public void misc() {
DynRealmTO dynRealm = null;
try {
dynRealm = new DynRealmTO();
dynRealm.setKey("/name" + getUUIDString());
dynRealm.getDynMembershipConds().put(AnyTypeKind.USER.name(), "cool==true");
// invalid key (starts with /)
try {
dynRealmService.create(dynRealm);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidDynRealm, e.getType());
}
dynRealm.setKey("name" + getUUIDString());
Response response = dynRealmService.create(dynRealm);
dynRealm = getObject(response.getLocation(), DynRealmService.class, DynRealmTO.class);
assertNotNull(dynRealm);
PagedResult<UserTO> matching = userService.search(new AnyQuery.Builder().fiql("cool==true").build());
assertNotNull(matching);
assertNotEquals(0, matching.getSize());
UserTO user = matching.getResult().get(0);
assertTrue(user.getDynRealms().contains(dynRealm.getKey()));
} finally {
if (dynRealm != null) {
dynRealmService.delete(dynRealm.getKey());
}
}
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class TemplateEditor method doSave.
public void doSave(final IProgressMonitor monitor) {
final ITextEditor ite = (ITextEditor) getActiveEditor();
final String content = ite.getDocumentProvider().getDocument(ite.getEditorInput()).get();
Job saveJob = new Job(SAVE_TEMPLATE_LABEL) {
@Override
protected IStatus run(final IProgressMonitor arg0) {
try {
if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_HTML)) {
SyncopeView.setMailTemplateContent(ite.getTitleToolTip(), MailTemplateFormat.HTML, content);
} else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_TEXT)) {
SyncopeView.setMailTemplateContent(ite.getTitleToolTip(), MailTemplateFormat.TEXT, content);
} else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_CSV)) {
SyncopeView.setReportTemplateContent(ite.getTitleToolTip(), ReportTemplateFormat.CSV, content);
} else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_XSL_FO)) {
SyncopeView.setReportTemplateContent(ite.getTitleToolTip(), ReportTemplateFormat.FO, content);
} else if (ite.getTitle().equals(SyncopeView.TEMPLATE_FORMAT_XSL_HTML)) {
SyncopeView.setReportTemplateContent(ite.getTitleToolTip(), ReportTemplateFormat.HTML, content);
} else {
throw new Exception("Not a valid editor title");
}
} catch (final SyncopeClientException e) {
e.printStackTrace();
if (ClientExceptionType.NotFound.equals(e.getType())) {
/*
* If a deleted template is being edited
* close editor and display error
*/
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
TemplateEditor.this.getSite().getPage().closeEditor(TemplateEditor.this, false);
}
});
return new org.eclipse.core.runtime.Status(org.eclipse.core.runtime.Status.ERROR, Activator.PLUGIN_ID, "Template No longer exists");
}
} catch (final Exception e) {
e.printStackTrace();
} finally {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
ite.doSave(monitor);
}
});
}
if (monitor.isCanceled()) {
return org.eclipse.core.runtime.Status.CANCEL_STATUS;
}
return org.eclipse.core.runtime.Status.OK_STATUS;
}
};
saveJob.setUser(true);
saveJob.schedule();
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class AnyObjectDirectoryPanel method getActions.
@Override
public ActionsPanel<AnyObjectTO> getActions(final IModel<AnyObjectTO> model) {
final ActionsPanel<AnyObjectTO> panel = super.getActions(model);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
send(AnyObjectDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>(new AnyWrapper<>(new AnyObjectRestClient().read(model.getObject().getKey())), target));
}
}, ActionType.EDIT, StringUtils.join(new String[] { AnyEntitlement.READ.getFor(type), AnyEntitlement.UPDATE.getFor(type) }, ",")).setRealm(realm);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770645L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
final AnyObjectTO clone = SerializationUtils.clone(model.getObject());
clone.setKey(null);
send(AnyObjectDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<>(new AnyWrapper<>(clone), target));
}
@Override
protected boolean statusCondition(final AnyObjectTO modelObject) {
return addAjaxLink.isVisibleInHierarchy() && realm.startsWith(SyncopeConstants.ROOT_REALM);
}
}, ActionType.CLONE, AnyEntitlement.CREATE.getFor(type)).setRealm(realm);
if (wizardInModal) {
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770645L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
final IModel<AnyWrapper<AnyObjectTO>> formModel = new CompoundPropertyModel<>(new AnyWrapper<>(model.getObject()));
altDefaultModal.setFormModel(formModel);
target.add(altDefaultModal.setContent(new AnyStatusModal<>(altDefaultModal, pageRef, formModel.getObject().getInnerObject(), "resource", false)));
altDefaultModal.header(new Model<>(getString("any.edit", new Model<>(new AnyWrapper<>(model.getObject())))));
altDefaultModal.show(true);
}
}, ActionType.MANAGE_RESOURCES, AnyEntitlement.UPDATE.getFor(type)).setRealm(realm);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
target.add(utilityModal.setContent(new AnyPropagationTasks(utilityModal, AnyTypeKind.ANY_OBJECT, model.getObject().getKey(), pageRef)));
utilityModal.header(new StringResourceModel("any.propagation.tasks", model));
utilityModal.show(true);
}
}, ActionType.PROPAGATION_TASKS, StandardEntitlement.TASK_LIST);
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
target.add(utilityModal.setContent(new NotificationTasks(AnyTypeKind.ANY_OBJECT, model.getObject().getKey(), pageRef)));
utilityModal.header(new StringResourceModel("any.notification.tasks", model));
utilityModal.show(true);
target.add(utilityModal);
}
}, ActionType.NOTIFICATION_TASKS, StandardEntitlement.TASK_LIST);
}
panel.add(new ActionLink<AnyObjectTO>() {
private static final long serialVersionUID = -7978723352517770646L;
@Override
public void onClick(final AjaxRequestTarget target, final AnyObjectTO ignore) {
try {
restClient.delete(model.getObject().getETagValue(), model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
LOG.error("While deleting object {}", model.getObject().getKey(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
@Override
protected boolean statusCondition(final AnyObjectTO modelObject) {
return realm.startsWith(SyncopeConstants.ROOT_REALM);
}
}, ActionType.DELETE, AnyEntitlement.DELETE.getFor(type), true).setRealm(realm);
return panel;
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class NotificationWizardBuilder method getSchemas.
private List<String> getSchemas() {
AnyTypeTO type = null;
try {
type = anyTypeRestClient.read(AnyTypeKind.USER.name());
} catch (SyncopeClientException e) {
LOG.error("While reading all any types", e);
}
String[] anyTypeClasses = type == null ? new String[0] : type.getClasses().toArray(new String[] {});
List<String> result = new ArrayList<>();
result.add("username");
result.addAll(schemaRestClient.<PlainSchemaTO>getSchemas(SchemaType.PLAIN, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
result.addAll(schemaRestClient.<DerSchemaTO>getSchemas(SchemaType.DERIVED, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
result.addAll(schemaRestClient.<VirSchemaTO>getSchemas(SchemaType.VIRTUAL, null, anyTypeClasses).stream().map(EntityTO::getKey).collect(Collectors.toList()));
Collections.sort(result);
return result;
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class ApprovalDirectoryPanel method getActions.
@Override
public ActionsPanel<WorkflowFormTO> getActions(final IModel<WorkflowFormTO> model) {
final ActionsPanel<WorkflowFormTO> panel = super.getActions(model);
panel.add(new ActionLink<WorkflowFormTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
claimForm(model.getObject().getTaskId());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
target.add(container);
}
}, ActionLink.ActionType.CLAIM, StandardEntitlement.WORKFLOW_FORM_CLAIM);
panel.add(new ActionLink<WorkflowFormTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
manageApprovalModal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
target.add(manageApprovalModal.setContent(new ApprovalModal(manageApprovalModal, pageRef, model.getObject()) {
private static final long serialVersionUID = 5546519445061007248L;
@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
try {
super.onSubmit(target, form);
ApprovalDirectoryPanel.this.getTogglePanel().close(target);
} catch (SyncopeClientException e) {
SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
}));
manageApprovalModal.header(new Model<>(getString("approval.manage", new Model<>(model.getObject()))));
manageApprovalModal.show(true);
}
@Override
protected boolean statusCondition(final WorkflowFormTO modelObject) {
return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
}
}, ActionLink.ActionType.MANAGE_APPROVAL, StandardEntitlement.WORKFLOW_FORM_READ);
// SYNCOPE-1200 edit user while in approval state
panel.add(new ActionLink<WorkflowFormTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
modal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
WorkflowFormTO formTO = model.getObject();
UserTO newUserTO;
UserTO previousUserTO;
if (formTO.getUserPatch() == null) {
newUserTO = formTO.getUserTO();
previousUserTO = null;
} else if (formTO.getUserTO() == null) {
// make it stronger by handling possible NPE
previousUserTO = new UserTO();
previousUserTO.setKey(formTO.getUserPatch().getKey());
newUserTO = AnyOperations.patch(previousUserTO, formTO.getUserPatch());
} else {
previousUserTO = formTO.getUserTO();
formTO.getUserTO().setKey(formTO.getUserPatch().getKey());
formTO.getUserTO().setPassword(null);
newUserTO = AnyOperations.patch(formTO.getUserTO(), formTO.getUserPatch());
}
AjaxWizard.EditItemActionEvent<UserTO> editItemActionEvent = new AjaxWizard.EditItemActionEvent<>(newUserTO, target);
editItemActionEvent.forceModalPanel(new ApprovalUserWizardBuilder(model.getObject(), previousUserTO, newUserTO, new AnyTypeRestClient().read(AnyTypeKind.USER.name()).getClasses(), FormLayoutInfoUtils.fetch(Collections.singletonList(AnyTypeKind.USER.name())).getLeft(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
send(ApprovalDirectoryPanel.this, Broadcast.EXACT, editItemActionEvent);
}
@Override
protected boolean statusCondition(final WorkflowFormTO modelObject) {
return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
}
}, ActionLink.ActionType.EDIT_APPROVAL, StandardEntitlement.WORKFLOW_FORM_SUBMIT);
return panel;
}
Aggregations