use of com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo in project concord by walmartlabs.
the class UserManager method getOrCreate.
public Optional<UserEntry> getOrCreate(String username, String userDomain, UserType type, String displayName, String email, Set<String> roles) {
Optional<UserEntry> result = get(username, userDomain, type);
if (result.isPresent()) {
return result;
}
if (type == null) {
type = UserPrincipal.assertCurrent().getType();
}
UserInfoProvider provider = assertProvider(type);
UserInfo info = provider.getInfo(null, username, userDomain);
if (info != null) {
username = info.username();
userDomain = info.userDomain();
displayName = info.displayName();
email = info.email();
result = get(username, userDomain, type);
if (result.isPresent()) {
return result;
}
}
return Optional.of(create(username, userDomain, displayName, email, type, roles));
}
use of com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo in project concord by walmartlabs.
the class FormServiceV1 method submit.
public FormSubmitResult submit(ProcessKey processKey, String formName, Map<String, Object> data) {
Form form = get(processKey, formName);
if (form == null) {
throw new ProcessException(processKey, "Form not found: " + formName);
}
ResumeHandler resumeHandler = (f, args) -> {
String resource = path(Constants.Files.JOB_ATTACHMENTS_DIR_NAME, Constants.Files.JOB_STATE_DIR_NAME, Constants.Files.JOB_FORMS_DIR_NAME, formName);
stateManager.deleteFile(processKey, resource);
@SuppressWarnings("unchecked") Map<String, Object> clearedData = (Map<String, Object>) args.get(f.getFormDefinition().getName());
args.put(f.getFormDefinition().getName(), clearedData);
// TODO refactor into the process manager
Map<String, Object> m = new HashMap<>();
m.put(Constants.Request.ARGUMENTS_KEY, args);
if (data != null) {
m.put(Constants.Files.FORM_FILES, data.remove(Constants.Files.FORM_FILES));
}
Map<String, Object> opts = f.getOptions();
Object runAs = opts != null ? opts.get(Constants.Forms.RUN_AS_KEY) : null;
if (runAs != null) {
m.put(INTERNAL_RUN_AS_KEY, runAs);
}
resume(processKey, f.getEventName(), m);
};
Map<String, Object> merged = merge(form, data);
// optionally save the user who submitted the form
boolean saveSubmittedBy = MapUtils.getBoolean(form.getOptions(), Constants.Forms.SAVE_SUBMITTED_BY_KEY, false);
if (saveSubmittedBy) {
UserInfo i = userManager.getCurrentUserInfo();
merged.put(Constants.Forms.SUBMITTED_BY_KEY, i);
}
try {
FormValidator validator = createFormValidator(processKey, formName);
return toResult(processKey, form, DefaultFormService.submit(resumeHandler, validator, form, merged));
} catch (ExecutionException e) {
throw new ProcessException(processKey, "Form submit error: " + e.getMessage(), e);
}
}
use of com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo in project concord by walmartlabs.
the class FormServiceV2 method submit.
public FormSubmitResult submit(ProcessKey processKey, String formName, Map<String, Object> data) throws FormUtils.ValidationException {
Form form = get(processKey, formName);
if (form == null) {
throw new ProcessException(processKey, "Form not found: " + formName);
}
FormValidatorLocale locale = new ExternalFileFormValidatorLocaleV2(processKey, formName, stateManager);
data = new LinkedHashMap<>(FormUtils.convert(locale, form, data));
// optionally save the user who submitted the form
boolean saveSubmittedBy = form.options().saveSubmittedBy();
if (saveSubmittedBy) {
UserInfo i = userManager.getCurrentUserInfo();
data.put(Constants.Forms.SUBMITTED_BY_KEY, i);
}
try {
FormValidator validator = new DefaultFormValidator(locale);
List<ValidationError> errors = validator.validate(form, data);
if (errors != null && !errors.isEmpty()) {
return new FormSubmitResult(processKey.getInstanceId(), form.name(), errors);
}
// the new form's values will be available under the form's name key
Map<String, Object> args = new LinkedHashMap<>();
args.put(form.name(), new LinkedHashMap<>(data));
// TODO refactor into the process manager
Map<String, Object> m = new HashMap<>();
m.put(Constants.Request.ARGUMENTS_KEY, args);
m.put(Constants.Files.FORM_FILES, data.remove(Constants.Files.FORM_FILES));
Object runAs = form.options().runAs();
if (runAs != null) {
m.put(INTERNAL_RUN_AS_KEY, runAs);
}
resume(processKey, form.eventName(), formName, m);
return new FormSubmitResult(processKey.getInstanceId(), form.name(), null);
} catch (Exception e) {
throw new ProcessException(processKey, "Form submit error: " + e.getMessage(), e);
}
}
Aggregations