code cleanup
This commit is contained in:
		
							parent
							
								
									2e13bf4ca2
								
							
						
					
					
						commit
						d2cfa615a1
					
				
					 20 changed files with 387 additions and 302 deletions
				
			
		|  | @ -16,14 +16,11 @@ import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.api.API; | import ch.ethz.seb.sebserver.gbl.api.API; | ||||||
| import ch.ethz.seb.sebserver.gbl.api.EntityType; | import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||||||
| import ch.ethz.seb.sebserver.gbl.authorization.PrivilegeType; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.model.Domain; | import ch.ethz.seb.sebserver.gbl.model.Domain; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.EntityKey; | import ch.ethz.seb.sebserver.gbl.model.EntityKey; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.institution.Institution; | import ch.ethz.seb.sebserver.gbl.model.institution.Institution; | ||||||
| import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.InstitutionActions; |  | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.UserAccountActions; |  | ||||||
| import ch.ethz.seb.sebserver.gui.form.FormBuilder; | import ch.ethz.seb.sebserver.gui.form.FormBuilder; | ||||||
| import ch.ethz.seb.sebserver.gui.form.FormHandle; | import ch.ethz.seb.sebserver.gui.form.FormHandle; | ||||||
| import ch.ethz.seb.sebserver.gui.form.PageFormService; | import ch.ethz.seb.sebserver.gui.form.PageFormService; | ||||||
|  | @ -31,11 +28,13 @@ import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext; | import ch.ethz.seb.sebserver.gui.service.page.PageContext; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageUtils; | import ch.ethz.seb.sebserver.gui.service.page.PageUtils; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.page.action.Action; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitution; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitution; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.NewInstitution; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.NewInstitution; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.SaveInstitution; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.SaveInstitution; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.EntityGrantCheck; | ||||||
| import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | ||||||
| 
 | 
 | ||||||
| @Lazy | @Lazy | ||||||
|  | @ -81,9 +80,10 @@ public class InstitutionForm implements TemplateComposer { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         final boolean writeGrant = this.currentUser.hasPrivilege(PrivilegeType.WRITE, institution); |         final EntityGrantCheck instGrant = this.currentUser.entityGrantCheck(institution); | ||||||
|         final boolean modifyGrant = this.currentUser.hasPrivilege(PrivilegeType.MODIFY, institution); |         final boolean writeGrant = instGrant.w(); | ||||||
|         final boolean userWriteGrant = this.currentUser.hasBasePrivilege(PrivilegeType.WRITE, EntityType.USER); |         final boolean modifyGrant = instGrant.m(); | ||||||
|  |         final boolean userWriteGrant = this.currentUser.grantCheck(EntityType.USER).w(); | ||||||
|         final boolean isReadonly = pageContext.isReadonly(); |         final boolean isReadonly = pageContext.isReadonly(); | ||||||
| 
 | 
 | ||||||
|         // new PageContext with actual EntityKey |         // new PageContext with actual EntityKey | ||||||
|  | @ -128,34 +128,37 @@ public class InstitutionForm implements TemplateComposer { | ||||||
|                         : this.restService.getRestCall(SaveInstitution.class)); |                         : this.restService.getRestCall(SaveInstitution.class)); | ||||||
| 
 | 
 | ||||||
|         // propagate content actions to action-pane |         // propagate content actions to action-pane | ||||||
|         formContext.createAction(ActionDefinition.INSTITUTION_NEW) |         formContext.clearEntityKeys() | ||||||
|                 .readonly(false) | 
 | ||||||
|  |                 .createAction(ActionDefinition.INSTITUTION_NEW) | ||||||
|                 .publishIf(() -> writeGrant && isReadonly) |                 .publishIf(() -> writeGrant && isReadonly) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_NEW) |                 .createAction(ActionDefinition.USER_ACCOUNT_NEW) | ||||||
|                 .withExec(UserAccountActions::newUserAccount) |                 .withParentEntityKey(entityKey) | ||||||
|                 .resetEntity() |  | ||||||
|                 .withParentEntity(entityKey) |  | ||||||
|                 .publishIf(() -> userWriteGrant && isReadonly && institution.isActive()) |                 .publishIf(() -> userWriteGrant && isReadonly && institution.isActive()) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.INSTITUTION_MODIFY) |                 .createAction(ActionDefinition.INSTITUTION_MODIFY) | ||||||
|                 .withExec(InstitutionActions::editInstitution) |                 .withEntityKey(entityKey) | ||||||
|                 .publishIf(() -> modifyGrant && isReadonly) |                 .publishIf(() -> modifyGrant && isReadonly) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.INSTITUTION_DEACTIVATE) |                 .createAction(ActionDefinition.INSTITUTION_DEACTIVATE) | ||||||
|                 .withExec(InstitutionActions::deactivateInstitution) |                 .withEntityKey(entityKey) | ||||||
|  |                 .withExec(Action.activation(this.restService, false)) | ||||||
|                 .withConfirm(PageUtils.confirmDeactivation(institution, this.restService)) |                 .withConfirm(PageUtils.confirmDeactivation(institution, this.restService)) | ||||||
|                 .publishIf(() -> writeGrant && isReadonly && institution.isActive()) |                 .publishIf(() -> writeGrant && isReadonly && institution.isActive()) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.INSTITUTION_ACTIVATE) |                 .createAction(ActionDefinition.INSTITUTION_ACTIVATE) | ||||||
|                 .withExec(InstitutionActions::activateInstitution) |                 .withEntityKey(entityKey) | ||||||
|  |                 .withExec(Action.activation(this.restService, true)) | ||||||
|                 .publishIf(() -> writeGrant && isReadonly && !institution.isActive()) |                 .publishIf(() -> writeGrant && isReadonly && !institution.isActive()) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.INSTITUTION_SAVE) |                 .createAction(ActionDefinition.INSTITUTION_SAVE) | ||||||
|                 .withExec(formHandle::postChanges) |                 .withExec(formHandle::postChanges) | ||||||
|                 .publishIf(() -> !isReadonly) |                 .publishIf(() -> !isReadonly) | ||||||
|  | 
 | ||||||
|                 .createAction(ActionDefinition.INSTITUTION_CANCEL_MODIFY) |                 .createAction(ActionDefinition.INSTITUTION_CANCEL_MODIFY) | ||||||
|                 .withExec(InstitutionActions::cancelEditInstitution) |                 .withEntityKey(entityKey) | ||||||
|  |                 .withExec(Action::onEmptyEntityKeyGoToActivityHome) | ||||||
|                 .withConfirm("sebserver.overall.action.modify.cancel.confirm") |                 .withConfirm("sebserver.overall.action.modify.cancel.confirm") | ||||||
|                 .publishIf(() -> !isReadonly); |                 .publishIf(() -> !isReadonly); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -13,19 +13,18 @@ import org.springframework.context.annotation.Lazy; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.api.EntityType; | import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||||||
| import ch.ethz.seb.sebserver.gbl.authorization.PrivilegeType; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.model.Domain; | import ch.ethz.seb.sebserver.gbl.model.Domain; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.institution.Institution; | import ch.ethz.seb.sebserver.gbl.model.institution.Institution; | ||||||
| import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.InstitutionActions; |  | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.UserAccountActions; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext; | import ch.ethz.seb.sebserver.gui.service.page.PageContext; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.page.action.Action; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitutions; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitutions; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; | ||||||
| import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; | import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.table.EntityTable; | import ch.ethz.seb.sebserver.gui.table.EntityTable; | ||||||
| import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | ||||||
|  | @ -77,21 +76,23 @@ public class InstitutionList implements TemplateComposer { | ||||||
|                         .compose(content); |                         .compose(content); | ||||||
| 
 | 
 | ||||||
|         // propagate content actions to action-pane |         // propagate content actions to action-pane | ||||||
|         pageContext.createAction(ActionDefinition.INSTITUTION_NEW) |         final GrantCheck instGrant = this.currentUser.grantCheck(EntityType.INSTITUTION); | ||||||
|                 .readonly(false) |         final GrantCheck userGrant = this.currentUser.grantCheck(EntityType.USER); | ||||||
|                 .publishIf(() -> this.currentUser.hasBasePrivilege(PrivilegeType.WRITE, EntityType.INSTITUTION)) |         pageContext.clearEntityKeys() | ||||||
|  | 
 | ||||||
|  |                 .createAction(ActionDefinition.INSTITUTION_NEW) | ||||||
|  |                 .publishIf(instGrant::w) | ||||||
|  | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_NEW) |                 .createAction(ActionDefinition.USER_ACCOUNT_NEW) | ||||||
|                 .withExec(UserAccountActions::newUserAccount) |                 .publishIf(userGrant::w) | ||||||
|                 .publishIf(() -> this.currentUser.hasBasePrivilege(PrivilegeType.WRITE, EntityType.USER)) | 
 | ||||||
|                 .createAction(ActionDefinition.INSTITUTION_VIEW_FROM_LIST) |                 .createAction(ActionDefinition.INSTITUTION_VIEW_FROM_LIST) | ||||||
|                 .withSelectionSupplier(table::getSelection) |                 .withSelect(table::getSelection, Action.applySingleSelection("sebserver.institution.info.pleaseSelect")) | ||||||
|                 .withExec(InstitutionActions::viewInstitutionFromList) |  | ||||||
|                 .publish() |                 .publish() | ||||||
|  | 
 | ||||||
|                 .createAction(ActionDefinition.INSTITUTION_MODIFY_FROM_LIST) |                 .createAction(ActionDefinition.INSTITUTION_MODIFY_FROM_LIST) | ||||||
|                 .withSelectionSupplier(table::getSelection) |                 .withSelect(table::getSelection, Action.applySingleSelection("sebserver.institution.info.pleaseSelect")) | ||||||
|                 .withExec(InstitutionActions::editInstitutionFromList) |                 .publishIf(instGrant::m); | ||||||
|                 .readonly(false) |  | ||||||
|                 .publishIf(() -> this.currentUser.hasBasePrivilege(PrivilegeType.MODIFY, EntityType.INSTITUTION)); |  | ||||||
|         ; |         ; | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -21,7 +21,6 @@ import ch.ethz.seb.sebserver.gbl.model.user.PasswordChange; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; | import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; | ||||||
| import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.UserAccountActions; |  | ||||||
| import ch.ethz.seb.sebserver.gui.form.FormBuilder; | import ch.ethz.seb.sebserver.gui.form.FormBuilder; | ||||||
| import ch.ethz.seb.sebserver.gui.form.FormHandle; | import ch.ethz.seb.sebserver.gui.form.FormHandle; | ||||||
| import ch.ethz.seb.sebserver.gui.form.PageFormService; | import ch.ethz.seb.sebserver.gui.form.PageFormService; | ||||||
|  | @ -29,6 +28,7 @@ import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; | ||||||
| import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext; | import ch.ethz.seb.sebserver.gui.service.page.PageContext; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.page.action.Action; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.ChangePassword; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.ChangePassword; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccount; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccount; | ||||||
|  | @ -115,7 +115,7 @@ public class UserAccountChangePasswordForm implements TemplateComposer { | ||||||
|                 }) |                 }) | ||||||
|                 .publish() |                 .publish() | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_CANCEL_MODIFY) |                 .createAction(ActionDefinition.USER_ACCOUNT_CANCEL_MODIFY) | ||||||
|                 .withExec(UserAccountActions::cancelEditUserAccount) |                 .withExec(Action::onEmptyEntityKeyGoToActivityHome) | ||||||
|                 .withConfirm("sebserver.overall.action.modify.cancel.confirm") |                 .withConfirm("sebserver.overall.action.modify.cancel.confirm") | ||||||
|                 .publish(); |                 .publish(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -20,7 +20,6 @@ import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.Constants; | import ch.ethz.seb.sebserver.gbl.Constants; | ||||||
| import ch.ethz.seb.sebserver.gbl.api.API; | import ch.ethz.seb.sebserver.gbl.api.API; | ||||||
| import ch.ethz.seb.sebserver.gbl.authorization.PrivilegeType; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.model.Domain; | import ch.ethz.seb.sebserver.gbl.model.Domain; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.Domain.USER_ROLE; | import ch.ethz.seb.sebserver.gbl.model.Domain.USER_ROLE; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.EntityKey; | import ch.ethz.seb.sebserver.gbl.model.EntityKey; | ||||||
|  | @ -31,7 +30,6 @@ import ch.ethz.seb.sebserver.gbl.model.user.UserMod; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.user.UserRole; | import ch.ethz.seb.sebserver.gbl.model.user.UserRole; | ||||||
| import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.UserAccountActions; |  | ||||||
| import ch.ethz.seb.sebserver.gui.form.FormBuilder; | import ch.ethz.seb.sebserver.gui.form.FormBuilder; | ||||||
| import ch.ethz.seb.sebserver.gui.form.FormHandle; | import ch.ethz.seb.sebserver.gui.form.FormHandle; | ||||||
| import ch.ethz.seb.sebserver.gui.form.PageFormService; | import ch.ethz.seb.sebserver.gui.form.PageFormService; | ||||||
|  | @ -46,6 +44,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUs | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.NewUserAccount; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.NewUserAccount; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.SaveUserAccount; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.SaveUserAccount; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.EntityGrantCheck; | ||||||
| import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | ||||||
| 
 | 
 | ||||||
| @Lazy | @Lazy | ||||||
|  | @ -72,13 +71,13 @@ public class UserAccountForm implements TemplateComposer { | ||||||
|     @Override |     @Override | ||||||
|     public void compose(final PageContext pageContext) { |     public void compose(final PageContext pageContext) { | ||||||
| 
 | 
 | ||||||
|         final UserInfo currentUser = this.currentUser.get(); |         final UserInfo user = this.currentUser.get(); | ||||||
|         final WidgetFactory widgetFactory = this.pageFormService.getWidgetFactory(); |         final WidgetFactory widgetFactory = this.pageFormService.getWidgetFactory(); | ||||||
|         final EntityKey entityKey = pageContext.getEntityKey(); |         final EntityKey entityKey = pageContext.getEntityKey(); | ||||||
|         final EntityKey parentEntityKey = pageContext.getParentEntityKey(); |         final EntityKey parentEntityKey = pageContext.getParentEntityKey(); | ||||||
|         final BooleanSupplier isNew = () -> entityKey == null; |         final BooleanSupplier isNew = () -> entityKey == null; | ||||||
|         final BooleanSupplier isNotNew = () -> !isNew.getAsBoolean(); |         final BooleanSupplier isNotNew = () -> !isNew.getAsBoolean(); | ||||||
|         final BooleanSupplier isSEBAdmin = () -> currentUser.hasRole(UserRole.SEB_SERVER_ADMIN); |         final BooleanSupplier isSEBAdmin = () -> user.hasRole(UserRole.SEB_SERVER_ADMIN); | ||||||
|         final boolean readonly = pageContext.isReadonly(); |         final boolean readonly = pageContext.isReadonly(); | ||||||
|         // get data or create new. handle error if happen |         // get data or create new. handle error if happen | ||||||
|         final UserAccount userAccount = isNew.getAsBoolean() |         final UserAccount userAccount = isNew.getAsBoolean() | ||||||
|  | @ -86,7 +85,7 @@ public class UserAccountForm implements TemplateComposer { | ||||||
|                         UUID.randomUUID().toString(), |                         UUID.randomUUID().toString(), | ||||||
|                         (parentEntityKey != null) |                         (parentEntityKey != null) | ||||||
|                                 ? Long.valueOf(parentEntityKey.modelId) |                                 ? Long.valueOf(parentEntityKey.modelId) | ||||||
|                                 : currentUser.institutionId) |                                 : user.institutionId) | ||||||
|                 : this.restService |                 : this.restService | ||||||
|                         .getBuilder(GetUserAccount.class) |                         .getBuilder(GetUserAccount.class) | ||||||
|                         .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) |                         .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) | ||||||
|  | @ -101,9 +100,10 @@ public class UserAccountForm implements TemplateComposer { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         final boolean ownAccount = currentUser.uuid.equals(userAccount.getModelId()); |         final boolean ownAccount = user.uuid.equals(userAccount.getModelId()); | ||||||
|         final boolean writeGrant = this.currentUser.hasPrivilege(PrivilegeType.WRITE, userAccount); |         final EntityGrantCheck userGrantCheck = this.currentUser.entityGrantCheck(userAccount); | ||||||
|         final boolean modifyGrant = this.currentUser.hasPrivilege(PrivilegeType.MODIFY, userAccount); |         final boolean writeGrant = userGrantCheck.w(); | ||||||
|  |         final boolean modifyGrant = userGrantCheck.m(); | ||||||
|         // modifying an UserAccount is not possible if the root institution is inactive |         // modifying an UserAccount is not possible if the root institution is inactive | ||||||
|         final boolean istitutionActive = this.restService.getBuilder(GetInstitution.class) |         final boolean istitutionActive = this.restService.getBuilder(GetInstitution.class) | ||||||
|                 .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(userAccount.getInstitutionId())) |                 .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(userAccount.getInstitutionId())) | ||||||
|  | @ -190,26 +190,26 @@ public class UserAccountForm implements TemplateComposer { | ||||||
| 
 | 
 | ||||||
|         // propagate content actions to action-pane |         // propagate content actions to action-pane | ||||||
| 
 | 
 | ||||||
|         formContext.createAction(ActionDefinition.USER_ACCOUNT_NEW) |         formContext.clearEntityKeys() | ||||||
|                 .resetEntity() | 
 | ||||||
|                 .withExec(UserAccountActions::newUserAccount) |                 .createAction(ActionDefinition.USER_ACCOUNT_NEW) | ||||||
|                 .publishIf(() -> writeGrant && readonly && istitutionActive) |                 .publishIf(() -> writeGrant && readonly && istitutionActive) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_MODIFY) |                 .createAction(ActionDefinition.USER_ACCOUNT_MODIFY) | ||||||
|                 .withExec(UserAccountActions::editUserAccount) |                 .withEntityKey(entityKey) | ||||||
|                 .publishIf(() -> modifyGrant && readonly && istitutionActive) |                 .publishIf(() -> modifyGrant && readonly && istitutionActive) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_CHANGE_PASSOWRD) |                 .createAction(ActionDefinition.USER_ACCOUNT_CHANGE_PASSOWRD) | ||||||
|                 .withEntity(userAccount.getEntityKey()) |                 .withEntityKey(entityKey) | ||||||
|                 .publishIf(() -> modifyGrant && readonly && istitutionActive && userAccount.isActive()) |                 .publishIf(() -> modifyGrant && readonly && istitutionActive && userAccount.isActive()) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_DEACTIVATE) |                 .createAction(ActionDefinition.USER_ACCOUNT_DEACTIVATE) | ||||||
|                 .withExec(UserAccountActions::deactivateUserAccount) |                 .withExec(Action.activation(this.restService, false)) | ||||||
|                 .withConfirm(PageUtils.confirmDeactivation(userAccount, this.restService)) |                 .withConfirm(PageUtils.confirmDeactivation(userAccount, this.restService)) | ||||||
|                 .publishIf(() -> writeGrant && readonly && istitutionActive && userAccount.isActive()) |                 .publishIf(() -> writeGrant && readonly && istitutionActive && userAccount.isActive()) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_ACTIVATE) |                 .createAction(ActionDefinition.USER_ACCOUNT_ACTIVATE) | ||||||
|                 .withExec(UserAccountActions::activateUserAccount) |                 .withExec(Action.activation(this.restService, true)) | ||||||
|                 .publishIf(() -> writeGrant && readonly && istitutionActive && !userAccount.isActive()) |                 .publishIf(() -> writeGrant && readonly && istitutionActive && !userAccount.isActive()) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_SAVE) |                 .createAction(ActionDefinition.USER_ACCOUNT_SAVE) | ||||||
|  | @ -224,7 +224,7 @@ public class UserAccountForm implements TemplateComposer { | ||||||
|                 .publishIf(() -> !readonly) |                 .publishIf(() -> !readonly) | ||||||
| 
 | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_CANCEL_MODIFY) |                 .createAction(ActionDefinition.USER_ACCOUNT_CANCEL_MODIFY) | ||||||
|                 .withExec(UserAccountActions::cancelEditUserAccount) |                 .withExec(Action::onEmptyEntityKeyGoToActivityHome) | ||||||
|                 .withConfirm("sebserver.overall.action.modify.cancel.confirm") |                 .withConfirm("sebserver.overall.action.modify.cancel.confirm") | ||||||
|                 .publishIf(() -> !readonly); |                 .publishIf(() -> !readonly); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -14,18 +14,18 @@ import org.springframework.context.annotation.Lazy; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.api.EntityType; | import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||||||
| import ch.ethz.seb.sebserver.gbl.authorization.PrivilegeType; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.model.Domain; | import ch.ethz.seb.sebserver.gbl.model.Domain; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; | import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; | ||||||
| import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.UserAccountActions; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext; | import ch.ethz.seb.sebserver.gui.service.page.PageContext; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.page.action.Action; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccounts; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccounts; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; | ||||||
| import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; | import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.table.ColumnDefinition.TableFilterAttribute; | import ch.ethz.seb.sebserver.gui.table.ColumnDefinition.TableFilterAttribute; | ||||||
| import ch.ethz.seb.sebserver.gui.table.EntityTable; | import ch.ethz.seb.sebserver.gui.table.EntityTable; | ||||||
|  | @ -97,17 +97,19 @@ public class UserAccountList implements TemplateComposer { | ||||||
|                         .compose(content); |                         .compose(content); | ||||||
| 
 | 
 | ||||||
|         // propagate content actions to action-pane |         // propagate content actions to action-pane | ||||||
|         pageContext.createAction(ActionDefinition.USER_ACCOUNT_NEW) |         final GrantCheck userGrant = this.currentUser.grantCheck(EntityType.USER); | ||||||
|                 .withExec(UserAccountActions::newUserAccount) |         pageContext.clearEntityKeys() | ||||||
|                 .publishIf(() -> this.currentUser.hasInstitutionalPrivilege(PrivilegeType.WRITE, EntityType.USER)) | 
 | ||||||
|  |                 .createAction(ActionDefinition.USER_ACCOUNT_NEW) | ||||||
|  |                 .publishIf(userGrant::w) | ||||||
|  | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_VIEW) |                 .createAction(ActionDefinition.USER_ACCOUNT_VIEW) | ||||||
|                 .withSelectionSupplier(table::getSelection) |                 .withSelect(table::getSelection, Action.applySingleSelection("sebserver.useraccount.info.pleaseSelect")) | ||||||
|                 .withExec(UserAccountActions::viewUserAccountFromList) |  | ||||||
|                 .publish() |                 .publish() | ||||||
|  | 
 | ||||||
|                 .createAction(ActionDefinition.USER_ACCOUNT_MODIFY_FROM_LIST) |                 .createAction(ActionDefinition.USER_ACCOUNT_MODIFY_FROM_LIST) | ||||||
|                 .withSelectionSupplier(table::getSelection) |                 .withSelect(table::getSelection, Action.applySingleSelection("sebserver.useraccount.info.pleaseSelect")) | ||||||
|                 .withExec(UserAccountActions::editUserAccountFromList) |                 .publishIf(userGrant::m); | ||||||
|                 .publishIf(() -> this.currentUser.hasInstitutionalPrivilege(PrivilegeType.MODIFY, EntityType.USER)); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private String getLocaleDisplayText(final UserInfo userInfo) { |     private String getLocaleDisplayText(final UserInfo userInfo) { | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ public enum ActionDefinition { | ||||||
|             new LocTextKey("sebserver.institution.action.new"), |             new LocTextKey("sebserver.institution.action.new"), | ||||||
|             ImageIcon.NEW, |             ImageIcon.NEW, | ||||||
|             InstitutionForm.class, |             InstitutionForm.class, | ||||||
|             INSTITUTION_VIEW_LIST), |             INSTITUTION_VIEW_LIST, false), | ||||||
|     INSTITUTION_VIEW_FROM_LIST( |     INSTITUTION_VIEW_FROM_LIST( | ||||||
|             new LocTextKey("sebserver.institution.action.list.view"), |             new LocTextKey("sebserver.institution.action.list.view"), | ||||||
|             ImageIcon.SHOW, |             ImageIcon.SHOW, | ||||||
|  | @ -41,13 +41,13 @@ public enum ActionDefinition { | ||||||
|             new LocTextKey("sebserver.institution.action.list.modify"), |             new LocTextKey("sebserver.institution.action.list.modify"), | ||||||
|             ImageIcon.EDIT, |             ImageIcon.EDIT, | ||||||
|             InstitutionForm.class, |             InstitutionForm.class, | ||||||
|             INSTITUTION_VIEW_LIST), |             INSTITUTION_VIEW_LIST, false), | ||||||
| 
 | 
 | ||||||
|     INSTITUTION_MODIFY( |     INSTITUTION_MODIFY( | ||||||
|             new LocTextKey("sebserver.institution.action.modify"), |             new LocTextKey("sebserver.institution.action.modify"), | ||||||
|             ImageIcon.EDIT, |             ImageIcon.EDIT, | ||||||
|             InstitutionForm.class, |             InstitutionForm.class, | ||||||
|             INSTITUTION_VIEW_LIST), |             INSTITUTION_VIEW_LIST, false), | ||||||
| 
 | 
 | ||||||
|     INSTITUTION_CANCEL_MODIFY( |     INSTITUTION_CANCEL_MODIFY( | ||||||
|             new LocTextKey("sebserver.overall.action.modify.cancel"), |             new LocTextKey("sebserver.overall.action.modify.cancel"), | ||||||
|  | @ -90,7 +90,7 @@ public enum ActionDefinition { | ||||||
|             new LocTextKey("sebserver.useraccount.action.new"), |             new LocTextKey("sebserver.useraccount.action.new"), | ||||||
|             ImageIcon.NEW, |             ImageIcon.NEW, | ||||||
|             UserAccountForm.class, |             UserAccountForm.class, | ||||||
|             USER_ACCOUNT_VIEW_LIST), |             USER_ACCOUNT_VIEW_LIST, false), | ||||||
| 
 | 
 | ||||||
|     USER_ACCOUNT_VIEW( |     USER_ACCOUNT_VIEW( | ||||||
|             new LocTextKey("sebserver.useraccount.action.view"), |             new LocTextKey("sebserver.useraccount.action.view"), | ||||||
|  | @ -102,13 +102,13 @@ public enum ActionDefinition { | ||||||
|             new LocTextKey("sebserver.useraccount.action.list.modify"), |             new LocTextKey("sebserver.useraccount.action.list.modify"), | ||||||
|             ImageIcon.EDIT, |             ImageIcon.EDIT, | ||||||
|             UserAccountForm.class, |             UserAccountForm.class, | ||||||
|             USER_ACCOUNT_VIEW_LIST), |             USER_ACCOUNT_VIEW_LIST, false), | ||||||
| 
 | 
 | ||||||
|     USER_ACCOUNT_MODIFY( |     USER_ACCOUNT_MODIFY( | ||||||
|             new LocTextKey("sebserver.useraccount.action.modify"), |             new LocTextKey("sebserver.useraccount.action.modify"), | ||||||
|             ImageIcon.EDIT, |             ImageIcon.EDIT, | ||||||
|             UserAccountForm.class, |             UserAccountForm.class, | ||||||
|             USER_ACCOUNT_VIEW_LIST), |             USER_ACCOUNT_VIEW_LIST, false), | ||||||
| 
 | 
 | ||||||
|     USER_ACCOUNT_CANCEL_MODIFY( |     USER_ACCOUNT_CANCEL_MODIFY( | ||||||
|             new LocTextKey("sebserver.overall.action.modify.cancel"), |             new LocTextKey("sebserver.overall.action.modify.cancel"), | ||||||
|  | @ -144,7 +144,7 @@ public enum ActionDefinition { | ||||||
|             new LocTextKey("sebserver.useraccount.action.change.password"), |             new LocTextKey("sebserver.useraccount.action.change.password"), | ||||||
|             ImageIcon.EDIT, |             ImageIcon.EDIT, | ||||||
|             UserAccountChangePasswordForm.class, |             UserAccountChangePasswordForm.class, | ||||||
|             USER_ACCOUNT_VIEW_LIST), |             USER_ACCOUNT_VIEW_LIST, false), | ||||||
|     USER_ACCOUNT_CHANGE_PASSOWRD_SAVE( |     USER_ACCOUNT_CHANGE_PASSOWRD_SAVE( | ||||||
|             new LocTextKey("sebserver.useraccount.action.change.password.save"), |             new LocTextKey("sebserver.useraccount.action.change.password.save"), | ||||||
|             ImageIcon.SAVE, |             ImageIcon.SAVE, | ||||||
|  | @ -158,6 +158,7 @@ public enum ActionDefinition { | ||||||
|     public final Class<? extends TemplateComposer> contentPaneComposer; |     public final Class<? extends TemplateComposer> contentPaneComposer; | ||||||
|     public final Class<? extends TemplateComposer> actionPaneComposer; |     public final Class<? extends TemplateComposer> actionPaneComposer; | ||||||
|     public final ActionDefinition activityAlias; |     public final ActionDefinition activityAlias; | ||||||
|  |     public final boolean readonly; | ||||||
| 
 | 
 | ||||||
|     private ActionDefinition( |     private ActionDefinition( | ||||||
|             final LocTextKey title, |             final LocTextKey title, | ||||||
|  | @ -168,6 +169,7 @@ public enum ActionDefinition { | ||||||
|         this.contentPaneComposer = contentPaneComposer; |         this.contentPaneComposer = contentPaneComposer; | ||||||
|         this.actionPaneComposer = ActionPane.class; |         this.actionPaneComposer = ActionPane.class; | ||||||
|         this.activityAlias = null; |         this.activityAlias = null; | ||||||
|  |         this.readonly = true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private ActionDefinition( |     private ActionDefinition( | ||||||
|  | @ -180,6 +182,7 @@ public enum ActionDefinition { | ||||||
|         this.contentPaneComposer = contentPaneComposer; |         this.contentPaneComposer = contentPaneComposer; | ||||||
|         this.actionPaneComposer = ActionPane.class; |         this.actionPaneComposer = ActionPane.class; | ||||||
|         this.activityAlias = activityAlias; |         this.activityAlias = activityAlias; | ||||||
|  |         this.readonly = true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private ActionDefinition( |     private ActionDefinition( | ||||||
|  | @ -193,20 +196,22 @@ public enum ActionDefinition { | ||||||
|         this.contentPaneComposer = contentPaneComposer; |         this.contentPaneComposer = contentPaneComposer; | ||||||
|         this.actionPaneComposer = ActionPane.class; |         this.actionPaneComposer = ActionPane.class; | ||||||
|         this.activityAlias = activityAlias; |         this.activityAlias = activityAlias; | ||||||
|  |         this.readonly = true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private ActionDefinition( |     private ActionDefinition( | ||||||
|             final LocTextKey title, |             final LocTextKey title, | ||||||
|             final ImageIcon icon, |             final ImageIcon icon, | ||||||
|             final Class<? extends TemplateComposer> contentPaneComposer, |             final Class<? extends TemplateComposer> contentPaneComposer, | ||||||
|             final Class<? extends TemplateComposer> actionPaneComposer, |             final ActionDefinition activityAlias, | ||||||
|             final ActionDefinition activityAlias) { |             final boolean readonly) { | ||||||
| 
 | 
 | ||||||
|         this.title = title; |         this.title = title; | ||||||
|         this.icon = icon; |         this.icon = icon; | ||||||
|         this.contentPaneComposer = contentPaneComposer; |         this.contentPaneComposer = contentPaneComposer; | ||||||
|         this.actionPaneComposer = actionPaneComposer; |         this.actionPaneComposer = ActionPane.class; | ||||||
|         this.activityAlias = activityAlias; |         this.activityAlias = activityAlias; | ||||||
|  |         this.readonly = readonly; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,94 +0,0 @@ | ||||||
| /* |  | ||||||
|  * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) |  | ||||||
|  * |  | ||||||
|  * This Source Code Form is subject to the terms of the Mozilla Public |  | ||||||
|  * License, v. 2.0. If a copy of the MPL was not distributed with this |  | ||||||
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package ch.ethz.seb.sebserver.gui.content.action; |  | ||||||
| 
 |  | ||||||
| import java.util.Collection; |  | ||||||
| 
 |  | ||||||
| import ch.ethz.seb.sebserver.gbl.api.API; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.api.EntityType; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.model.EntityKey; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext.AttributeKeys; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageMessageException; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.action.Action; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.event.ActionEvent; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.ActivateInstitution; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.DeactivateInstitution; |  | ||||||
| 
 |  | ||||||
| /** Defines the action execution functions for all Institution action. */ |  | ||||||
| public final class InstitutionActions { |  | ||||||
| 
 |  | ||||||
|     public static Action viewInstitutionFromList(final Action action) { |  | ||||||
|         return fromSelection(action, false); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static Action editInstitutionFromList(final Action action) { |  | ||||||
|         return fromSelection(action, true); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static Action editInstitution(final Action action) { |  | ||||||
|         return goToInstitution(action, null, true); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static Action cancelEditInstitution(final Action action) { |  | ||||||
|         if (action.getEntityKey() == null) { |  | ||||||
|             final PageContext pageContext = action.pageContext(); |  | ||||||
|             final Action toList = pageContext.createAction(ActionDefinition.INSTITUTION_VIEW_LIST); |  | ||||||
|             pageContext.publishPageEvent(new ActionEvent(toList, false)); |  | ||||||
|             return toList; |  | ||||||
|         } else { |  | ||||||
|             return goToInstitution(action, null, false); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static Action activateInstitution(final Action action) { |  | ||||||
|         return action.restService |  | ||||||
|                 .getBuilder(ActivateInstitution.class) |  | ||||||
|                 .withURIVariable( |  | ||||||
|                         API.PARAM_MODEL_ID, |  | ||||||
|                         action.pageContext().getAttribute(AttributeKeys.ENTITY_ID)) |  | ||||||
|                 .call() |  | ||||||
|                 .map(report -> goToInstitution(action, report.getSingleSource().modelId, false)) |  | ||||||
|                 .getOrThrow(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static Action deactivateInstitution(final Action action) { |  | ||||||
|         return action.restService |  | ||||||
|                 .getBuilder(DeactivateInstitution.class) |  | ||||||
|                 .withURIVariable( |  | ||||||
|                         API.PARAM_MODEL_ID, |  | ||||||
|                         action.pageContext().getAttribute(AttributeKeys.ENTITY_ID)) |  | ||||||
|                 .call() |  | ||||||
|                 .map(report -> goToInstitution(action, report.getSingleSource().modelId, false)) |  | ||||||
|                 .getOrThrow(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private static Action fromSelection(final Action action, final boolean edit) { |  | ||||||
|         final Collection<String> selection = action.getSelectionSupplier().get(); |  | ||||||
|         if (selection.isEmpty()) { |  | ||||||
|             throw new PageMessageException("sebserver.institution.info.pleaseSelect"); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return goToInstitution(action, selection.iterator().next(), edit); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private static Action goToInstitution( |  | ||||||
|             final Action action, |  | ||||||
|             final String modelId, |  | ||||||
|             final boolean edit) { |  | ||||||
| 
 |  | ||||||
|         action.withAttribute(AttributeKeys.READ_ONLY, String.valueOf(!edit)); |  | ||||||
|         if (modelId != null) { |  | ||||||
|             action.withEntity(new EntityKey(modelId, EntityType.INSTITUTION)); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return action; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
|  | @ -8,88 +8,54 @@ | ||||||
| 
 | 
 | ||||||
| package ch.ethz.seb.sebserver.gui.content.action; | package ch.ethz.seb.sebserver.gui.content.action; | ||||||
| 
 | 
 | ||||||
| import java.util.Collection; |  | ||||||
| 
 |  | ||||||
| import ch.ethz.seb.sebserver.gbl.api.API; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.api.EntityType; |  | ||||||
| import ch.ethz.seb.sebserver.gbl.model.EntityKey; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext.AttributeKeys; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageMessageException; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.action.Action; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.event.ActionEvent; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.ActivateUserAccount; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.DeactivateUserAccount; |  | ||||||
| 
 |  | ||||||
| public final class UserAccountActions { | public final class UserAccountActions { | ||||||
| 
 | 
 | ||||||
|     public static Action newUserAccount(final Action action) { | //    public static Action newUserAccount(final Action action) { | ||||||
|         return goToUserAccount(action, null, true); | //        return goToUserAccount(action, null, true); | ||||||
|     } | //    } | ||||||
| 
 | // | ||||||
|     public static Action viewUserAccountFromList(final Action action) { | //    public static Action viewUserAccountFromList(final Action action) { | ||||||
|         return fromSelection(action, false); | //        return fromSelection(action, false); | ||||||
|     } | //    } | ||||||
| 
 | // | ||||||
|     public static Action editUserAccountFromList(final Action action) { | //    public static Action editUserAccountFromList(final Action action) { | ||||||
|         return fromSelection(action, true); | //        return fromSelection(action, true); | ||||||
|     } | //    } | ||||||
| 
 | // | ||||||
|     public static Action editUserAccount(final Action action) { | //    public static Action editUserAccount(final Action action) { | ||||||
|         return goToUserAccount(action, null, true); | //        return goToUserAccount(action, null, true); | ||||||
|     } | //    } | ||||||
| 
 | // | ||||||
|     public static Action cancelEditUserAccount(final Action action) { | //    public static Action cancelEditUserAccount(final Action action) { | ||||||
|         if (action.pageContext().getEntityKey() == null) { | //        if (action.pageContext().getEntityKey() == null) { | ||||||
|             final Action toList = action.pageContext().createAction(ActionDefinition.USER_ACCOUNT_VIEW_LIST); | //            final Action toList = action.pageContext().createAction(ActionDefinition.USER_ACCOUNT_VIEW_LIST); | ||||||
|             action.pageContext().publishPageEvent(new ActionEvent(toList, false)); | //            action.pageContext().publishPageEvent(new ActionEvent(toList, false)); | ||||||
|             return toList; | //            return toList; | ||||||
|         } else { | //        } else { | ||||||
|             return goToUserAccount(action, null, false); | //            return goToUserAccount(action, null, false); | ||||||
|         } | //        } | ||||||
|     } | //    } | ||||||
| 
 | // | ||||||
|     public static Action activateUserAccount(final Action action) { | //    private static Action fromSelection(final Action action, final boolean edit) { | ||||||
|         return action.restService | //        final Collection<String> selection = action.getSelectionSupplier().get(); | ||||||
|                 .getBuilder(ActivateUserAccount.class) | //        if (selection.isEmpty()) { | ||||||
|                 .withURIVariable( | //            throw new PageMessageException("sebserver.useraccount.info.pleaseSelect"); | ||||||
|                         API.PARAM_MODEL_ID, | //        } | ||||||
|                         action.pageContext().getAttribute(AttributeKeys.ENTITY_ID)) | // | ||||||
|                 .call() | //        return goToUserAccount(action, selection.iterator().next(), edit); | ||||||
|                 .map(report -> goToUserAccount(action, report.getSingleSource().modelId, false)) | //    } | ||||||
|                 .getOrThrow(); | // | ||||||
|     } | //    private static Action goToUserAccount( | ||||||
| 
 | //            final Action action, | ||||||
|     public static Action deactivateUserAccount(final Action action) { | //            final String modelId, | ||||||
|         return action.restService | //            final boolean edit) { | ||||||
|                 .getBuilder(DeactivateUserAccount.class) | // | ||||||
|                 .withURIVariable( | //        action.withAttribute(AttributeKeys.READ_ONLY, String.valueOf(!edit)); | ||||||
|                         API.PARAM_MODEL_ID, | //        if (modelId != null) { | ||||||
|                         action.pageContext().getAttribute(AttributeKeys.ENTITY_ID)) | //            action.withEntity(new EntityKey(modelId, EntityType.USER)); | ||||||
|                 .call() | //        } | ||||||
|                 .map(report -> goToUserAccount(action, report.getSingleSource().modelId, false)) | // | ||||||
|                 .getOrThrow(); | //        return action; | ||||||
|     } | //    } | ||||||
| 
 |  | ||||||
|     private static Action fromSelection(final Action action, final boolean edit) { |  | ||||||
|         final Collection<String> selection = action.getSelectionSupplier().get(); |  | ||||||
|         if (selection.isEmpty()) { |  | ||||||
|             throw new PageMessageException("sebserver.useraccount.info.pleaseSelect"); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return goToUserAccount(action, selection.iterator().next(), edit); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private static Action goToUserAccount( |  | ||||||
|             final Action action, |  | ||||||
|             final String modelId, |  | ||||||
|             final boolean edit) { |  | ||||||
| 
 |  | ||||||
|         action.withAttribute(AttributeKeys.READ_ONLY, String.valueOf(!edit)); |  | ||||||
|         if (modelId != null) { |  | ||||||
|             action.withEntity(new EntityKey(modelId, EntityType.USER)); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return action; |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -92,7 +92,7 @@ public class ActivitiesPane implements TemplateComposer { | ||||||
|             injectActivitySelection( |             injectActivitySelection( | ||||||
|                     institutions, |                     institutions, | ||||||
|                     pageContext.createAction(ActionDefinition.INSTITUTION_VIEW_FORM) |                     pageContext.createAction(ActionDefinition.INSTITUTION_VIEW_FORM) | ||||||
|                             .withEntity(userInfo.institutionId, EntityType.INSTITUTION) |                             .withEntityKey(userInfo.institutionId, EntityType.INSTITUTION) | ||||||
|                             .withAttribute(AttributeKeys.READ_ONLY, "true")); |                             .withAttribute(AttributeKeys.READ_ONLY, "true")); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -113,7 +113,7 @@ public class ActivitiesPane implements TemplateComposer { | ||||||
|             injectActivitySelection( |             injectActivitySelection( | ||||||
|                     userAccounts, |                     userAccounts, | ||||||
|                     pageContext.createAction(ActionDefinition.USER_ACCOUNT_VIEW_FORM) |                     pageContext.createAction(ActionDefinition.USER_ACCOUNT_VIEW_FORM) | ||||||
|                             .withEntity(this.currentUser.get().getEntityKey()) |                             .withEntityKey(this.currentUser.get().getEntityKey()) | ||||||
|                             .withAttribute(AttributeKeys.READ_ONLY, "true")); |                             .withAttribute(AttributeKeys.READ_ONLY, "true")); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -67,7 +67,7 @@ public class FormHandle<T extends Entity> { | ||||||
|                 .map(result -> { |                 .map(result -> { | ||||||
|                     final Action action = this.pageContext.createAction(actionDefinition) |                     final Action action = this.pageContext.createAction(actionDefinition) | ||||||
|                             .withAttribute(AttributeKeys.READ_ONLY, "true") |                             .withAttribute(AttributeKeys.READ_ONLY, "true") | ||||||
|                             .withEntity(result.getEntityKey()); |                             .withEntityKey(result.getEntityKey()); | ||||||
|                     this.pageContext.publishPageEvent(new ActionEvent(action, false)); |                     this.pageContext.publishPageEvent(new ActionEvent(action, false)); | ||||||
|                     return action; |                     return action; | ||||||
|                 }) |                 }) | ||||||
|  |  | ||||||
|  | @ -131,6 +131,11 @@ public interface PageContext { | ||||||
|      * @return the new PageContext with the EntityKey added */ |      * @return the new PageContext with the EntityKey added */ | ||||||
|     PageContext withParentEntityKey(EntityKey entityKey); |     PageContext withParentEntityKey(EntityKey entityKey); | ||||||
| 
 | 
 | ||||||
|  |     /** Create a copy of this PageContext and resets both entity keys attributes, the base and the parent EntityKey | ||||||
|  |      * | ||||||
|  |      * @return copy of this PageContext with reseted EntityKey attributes (base and parent) */ | ||||||
|  |     PageContext clearEntityKeys(); | ||||||
|  | 
 | ||||||
|     /** Indicates if an attribute with the specified name exists within this PageContext |     /** Indicates if an attribute with the specified name exists within this PageContext | ||||||
|      * |      * | ||||||
|      * @param name the name of the attribute |      * @param name the name of the attribute | ||||||
|  | @ -205,4 +210,5 @@ public interface PageContext { | ||||||
|      * |      * | ||||||
|      * @param pme the PageMessageException */ |      * @param pme the PageMessageException */ | ||||||
|     void publishPageMessage(PageMessageException pme); |     void publishPageMessage(PageMessageException pme); | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -13,9 +13,11 @@ import java.util.function.BooleanSupplier; | ||||||
| import java.util.function.Function; | import java.util.function.Function; | ||||||
| import java.util.function.Supplier; | import java.util.function.Supplier; | ||||||
| 
 | 
 | ||||||
|  | import org.apache.commons.lang3.StringUtils; | ||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
| 
 | 
 | ||||||
|  | import ch.ethz.seb.sebserver.gbl.api.API; | ||||||
| import ch.ethz.seb.sebserver.gbl.api.EntityType; | import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.EntityKey; | import ch.ethz.seb.sebserver.gbl.model.EntityKey; | ||||||
| import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; | ||||||
|  | @ -27,18 +29,19 @@ import ch.ethz.seb.sebserver.gui.service.page.event.ActionEvent; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.event.ActionPublishEvent; | import ch.ethz.seb.sebserver.gui.service.page.event.ActionPublishEvent; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCallError; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCallError; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.ActivateInstitution; | ||||||
|  | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.DeactivateInstitution; | ||||||
| 
 | 
 | ||||||
| public final class Action implements Runnable { | public final class Action implements Runnable { | ||||||
| 
 | 
 | ||||||
|     private static final Logger log = LoggerFactory.getLogger(Action.class); |     private static final Logger log = LoggerFactory.getLogger(Action.class); | ||||||
| 
 | 
 | ||||||
|     public final RestService restService; |  | ||||||
|     public final ActionDefinition definition; |     public final ActionDefinition definition; | ||||||
|     Supplier<LocTextKey> confirm; |     Supplier<LocTextKey> confirm; | ||||||
|     LocTextKey successMessage; |     LocTextKey successMessage; | ||||||
|     boolean updateOnSelection; |     boolean updateOnSelection; | ||||||
| 
 | 
 | ||||||
|     Supplier<Set<String>> selectionSupplier; |     Supplier<Set<EntityKey>> selectionSupplier; | ||||||
| 
 | 
 | ||||||
|     private final PageContext originalPageContext; |     private final PageContext originalPageContext; | ||||||
|     private PageContext pageContext; |     private PageContext pageContext; | ||||||
|  | @ -46,13 +49,13 @@ public final class Action implements Runnable { | ||||||
| 
 | 
 | ||||||
|     public Action( |     public Action( | ||||||
|             final ActionDefinition definition, |             final ActionDefinition definition, | ||||||
|             final PageContext pageContext, |             final PageContext pageContext) { | ||||||
|             final RestService restService) { |  | ||||||
| 
 | 
 | ||||||
|         this.definition = definition; |         this.definition = definition; | ||||||
|         this.originalPageContext = pageContext; |         this.originalPageContext = pageContext; | ||||||
|         this.pageContext = pageContext; |         this.pageContext = pageContext.withAttribute( | ||||||
|         this.restService = restService; |                 AttributeKeys.READ_ONLY, | ||||||
|  |                 String.valueOf(definition.readonly)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | @ -70,7 +73,8 @@ public final class Action implements Runnable { | ||||||
|     private void exec() { |     private void exec() { | ||||||
|         try { |         try { | ||||||
| 
 | 
 | ||||||
|             this.pageContext.publishPageEvent(new ActionEvent(this.exec.apply(this), false)); |             final Action executedAction = this.exec.apply(this); | ||||||
|  |             this.pageContext.publishPageEvent(new ActionEvent(executedAction, false)); | ||||||
| 
 | 
 | ||||||
|         } catch (final PageMessageException pme) { |         } catch (final PageMessageException pme) { | ||||||
|             Action.this.pageContext.publishPageMessage(pme); |             Action.this.pageContext.publishPageMessage(pme); | ||||||
|  | @ -90,20 +94,22 @@ public final class Action implements Runnable { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Supplier<Set<String>> getSelectionSupplier() { |  | ||||||
|         return this.selectionSupplier; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public Action withExec(final Function<Action, Action> exec) { |     public Action withExec(final Function<Action, Action> exec) { | ||||||
|         this.exec = exec; |         this.exec = exec; | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action withSelectionSupplier(final Supplier<Set<String>> selectionSupplier) { |     public Action withSelectionSupplier(final Supplier<Set<EntityKey>> selectionSupplier) { | ||||||
|         this.selectionSupplier = selectionSupplier; |         this.selectionSupplier = selectionSupplier; | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public Action withSelect(final Supplier<Set<EntityKey>> selectionSupplier, final Function<Action, Action> exec) { | ||||||
|  |         this.selectionSupplier = selectionSupplier; | ||||||
|  |         this.exec = exec; | ||||||
|  |         return this; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public Action withConfirm(final String confirmationMessageKey) { |     public Action withConfirm(final String confirmationMessageKey) { | ||||||
|         this.confirm = () -> new LocTextKey(confirmationMessageKey); |         this.confirm = () -> new LocTextKey(confirmationMessageKey); | ||||||
|         return this; |         return this; | ||||||
|  | @ -124,12 +130,12 @@ public final class Action implements Runnable { | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action resetEntity() { |     public Action resetEntityKey() { | ||||||
|         this.pageContext = this.pageContext.withEntityKey(null); |         this.pageContext = this.pageContext.withEntityKey(null); | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action resetParentEntity() { |     public Action resetParentEntityKey() { | ||||||
|         this.pageContext = this.pageContext.withParentEntityKey(null); |         this.pageContext = this.pageContext.withParentEntityKey(null); | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  | @ -142,20 +148,20 @@ public final class Action implements Runnable { | ||||||
|         return this.pageContext; |         return this.pageContext; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action withEntity(final EntityKey entityKey) { |     public Action withEntityKey(final EntityKey entityKey) { | ||||||
|         this.pageContext = this.pageContext.withEntityKey(entityKey); |         this.pageContext = this.pageContext.withEntityKey(entityKey); | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action withEntity(final Long modelId, final EntityType entityType) { |     public Action withEntityKey(final Long modelId, final EntityType entityType) { | ||||||
|         if (modelId != null) { |         if (modelId != null) { | ||||||
|             return withEntity(String.valueOf(modelId), entityType); |             return withEntityKey(String.valueOf(modelId), entityType); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action withEntity(final String modelId, final EntityType entityType) { |     public Action withEntityKey(final String modelId, final EntityType entityType) { | ||||||
|         if (modelId == null || entityType == null) { |         if (modelId == null || entityType == null) { | ||||||
|             return this; |             return this; | ||||||
|         } |         } | ||||||
|  | @ -164,7 +170,7 @@ public final class Action implements Runnable { | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action withParentEntity(final EntityKey entityKey) { |     public Action withParentEntityKey(final EntityKey entityKey) { | ||||||
|         this.pageContext = this.pageContext.withParentEntityKey(entityKey); |         this.pageContext = this.pageContext.withParentEntityKey(entityKey); | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  | @ -187,8 +193,60 @@ public final class Action implements Runnable { | ||||||
|         return this.originalPageContext; |         return this.originalPageContext; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Action readonly(final boolean b) { |     public EntityKey getSingleSelection(final String messageOnEmptySelection) { | ||||||
|         return this.withAttribute(AttributeKeys.READ_ONLY, "false"); |         final Set<EntityKey> selection = getMultiSelection(messageOnEmptySelection); | ||||||
|  |         if (selection != null) { | ||||||
|  |             return selection.iterator().next(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public Set<EntityKey> getMultiSelection(final String messageOnEmptySelection) { | ||||||
|  |         if (this.selectionSupplier != null) { | ||||||
|  |             final Set<EntityKey> selection = this.selectionSupplier.get(); | ||||||
|  |             if (selection.isEmpty()) { | ||||||
|  |                 if (StringUtils.isNoneBlank(messageOnEmptySelection)) { | ||||||
|  |                     throw new PageMessageException(messageOnEmptySelection); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 return null; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return selection; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (StringUtils.isNoneBlank(messageOnEmptySelection)) { | ||||||
|  |             throw new PageMessageException(messageOnEmptySelection); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static Function<Action, Action> applySingleSelection(final String messageOnEmptySelection) { | ||||||
|  |         return action -> action.withEntityKey(action.getSingleSelection(messageOnEmptySelection)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static Function<Action, Action> activation(final RestService restService, final boolean activate) { | ||||||
|  |         return action -> restService | ||||||
|  |                 .getBuilder((activate) ? ActivateInstitution.class : DeactivateInstitution.class) | ||||||
|  |                 .withURIVariable( | ||||||
|  |                         API.PARAM_MODEL_ID, | ||||||
|  |                         action.pageContext().getAttribute(AttributeKeys.ENTITY_ID)) | ||||||
|  |                 .call() | ||||||
|  |                 .map(report -> action) | ||||||
|  |                 .getOrThrow(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static Action onEmptyEntityKeyGoToActivityHome(final Action action) { | ||||||
|  |         if (action.getEntityKey() == null) { | ||||||
|  |             final PageContext pageContext = action.pageContext(); | ||||||
|  |             final Action activityHomeAction = pageContext.createAction(action.definition.activityAlias); | ||||||
|  |             action.pageContext.publishPageEvent(new ActionEvent(activityHomeAction, false)); | ||||||
|  |             return activityHomeAction; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return action; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -25,7 +25,6 @@ import ch.ethz.seb.sebserver.gui.service.page.ComposerService; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext; | import ch.ethz.seb.sebserver.gui.service.page.PageContext; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageDefinition; | import ch.ethz.seb.sebserver.gui.service.page.PageDefinition; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.AuthorizationContextHolder; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.AuthorizationContextHolder; | ||||||
| import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; | ||||||
| 
 | 
 | ||||||
|  | @ -41,20 +40,17 @@ public class ComposerServiceImpl implements ComposerService { | ||||||
|     private final Class<? extends PageDefinition> mainPageType = DefaultMainPage.class; |     private final Class<? extends PageDefinition> mainPageType = DefaultMainPage.class; | ||||||
| 
 | 
 | ||||||
|     final AuthorizationContextHolder authorizationContextHolder; |     final AuthorizationContextHolder authorizationContextHolder; | ||||||
|     private final RestService restService; |  | ||||||
|     private final I18nSupport i18nSupport; |     private final I18nSupport i18nSupport; | ||||||
|     private final Map<String, TemplateComposer> composer; |     private final Map<String, TemplateComposer> composer; | ||||||
|     private final Map<String, PageDefinition> pages; |     private final Map<String, PageDefinition> pages; | ||||||
| 
 | 
 | ||||||
|     public ComposerServiceImpl( |     public ComposerServiceImpl( | ||||||
|             final AuthorizationContextHolder authorizationContextHolder, |             final AuthorizationContextHolder authorizationContextHolder, | ||||||
|             final RestService restService, |  | ||||||
|             final I18nSupport i18nSupport, |             final I18nSupport i18nSupport, | ||||||
|             final Collection<TemplateComposer> composer, |             final Collection<TemplateComposer> composer, | ||||||
|             final Collection<PageDefinition> pageDefinitions) { |             final Collection<PageDefinition> pageDefinitions) { | ||||||
| 
 | 
 | ||||||
|         this.authorizationContextHolder = authorizationContextHolder; |         this.authorizationContextHolder = authorizationContextHolder; | ||||||
|         this.restService = restService; |  | ||||||
|         this.i18nSupport = i18nSupport; |         this.i18nSupport = i18nSupport; | ||||||
|         this.composer = composer |         this.composer = composer | ||||||
|                 .stream() |                 .stream() | ||||||
|  | @ -178,7 +174,7 @@ public class ComposerServiceImpl implements ComposerService { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private PageContext createPageContext(final Composite root) { |     private PageContext createPageContext(final Composite root) { | ||||||
|         return new PageContextImpl(this.restService, this.i18nSupport, this, root, root, null); |         return new PageContextImpl(this.i18nSupport, this, root, root, null); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -38,7 +38,6 @@ import ch.ethz.seb.sebserver.gui.service.page.PageMessageException; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.action.Action; | import ch.ethz.seb.sebserver.gui.service.page.action.Action; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.event.PageEvent; | import ch.ethz.seb.sebserver.gui.service.page.event.PageEvent; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.event.PageEventListener; | import ch.ethz.seb.sebserver.gui.service.page.event.PageEventListener; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; |  | ||||||
| import ch.ethz.seb.sebserver.gui.widget.Message; | import ch.ethz.seb.sebserver.gui.widget.Message; | ||||||
| 
 | 
 | ||||||
| public class PageContextImpl implements PageContext { | public class PageContextImpl implements PageContext { | ||||||
|  | @ -47,7 +46,6 @@ public class PageContextImpl implements PageContext { | ||||||
| 
 | 
 | ||||||
|     private static final ListenerComparator LIST_COMPARATOR = new ListenerComparator(); |     private static final ListenerComparator LIST_COMPARATOR = new ListenerComparator(); | ||||||
| 
 | 
 | ||||||
|     private final RestService restService; |  | ||||||
|     private final I18nSupport i18nSupport; |     private final I18nSupport i18nSupport; | ||||||
|     private final ComposerService composerService; |     private final ComposerService composerService; | ||||||
|     private final Composite root; |     private final Composite root; | ||||||
|  | @ -55,14 +53,12 @@ public class PageContextImpl implements PageContext { | ||||||
|     private final Map<String, String> attributes; |     private final Map<String, String> attributes; | ||||||
| 
 | 
 | ||||||
|     PageContextImpl( |     PageContextImpl( | ||||||
|             final RestService restService, |  | ||||||
|             final I18nSupport i18nSupport, |             final I18nSupport i18nSupport, | ||||||
|             final ComposerService composerService, |             final ComposerService composerService, | ||||||
|             final Composite root, |             final Composite root, | ||||||
|             final Composite parent, |             final Composite parent, | ||||||
|             final Map<String, String> attributes) { |             final Map<String, String> attributes) { | ||||||
| 
 | 
 | ||||||
|         this.restService = restService; |  | ||||||
|         this.i18nSupport = i18nSupport; |         this.i18nSupport = i18nSupport; | ||||||
|         this.composerService = composerService; |         this.composerService = composerService; | ||||||
|         this.root = root; |         this.root = root; | ||||||
|  | @ -102,7 +98,6 @@ public class PageContextImpl implements PageContext { | ||||||
|     @Override |     @Override | ||||||
|     public PageContext copyOf(final Composite parent) { |     public PageContext copyOf(final Composite parent) { | ||||||
|         return new PageContextImpl( |         return new PageContextImpl( | ||||||
|                 this.restService, |  | ||||||
|                 this.i18nSupport, |                 this.i18nSupport, | ||||||
|                 this.composerService, |                 this.composerService, | ||||||
|                 this.root, |                 this.root, | ||||||
|  | @ -116,7 +111,6 @@ public class PageContextImpl implements PageContext { | ||||||
|         attrs.putAll(this.attributes); |         attrs.putAll(this.attributes); | ||||||
|         attrs.putAll(((PageContextImpl) otherContext).attributes); |         attrs.putAll(((PageContextImpl) otherContext).attributes); | ||||||
|         return new PageContextImpl( |         return new PageContextImpl( | ||||||
|                 this.restService, |  | ||||||
|                 this.i18nSupport, |                 this.i18nSupport, | ||||||
|                 this.composerService, |                 this.composerService, | ||||||
|                 this.root, |                 this.root, | ||||||
|  | @ -130,7 +124,6 @@ public class PageContextImpl implements PageContext { | ||||||
|         attrs.putAll(this.attributes); |         attrs.putAll(this.attributes); | ||||||
|         attrs.put(key, value); |         attrs.put(key, value); | ||||||
|         return new PageContextImpl( |         return new PageContextImpl( | ||||||
|                 this.restService, |  | ||||||
|                 this.i18nSupport, |                 this.i18nSupport, | ||||||
|                 this.composerService, |                 this.composerService, | ||||||
|                 this.root, |                 this.root, | ||||||
|  | @ -199,6 +192,12 @@ public class PageContextImpl implements PageContext { | ||||||
|                 .withAttribute(AttributeKeys.PARENT_ENTITY_TYPE, entityKey.entityType.name()); |                 .withAttribute(AttributeKeys.PARENT_ENTITY_TYPE, entityKey.entityType.name()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Override | ||||||
|  |     public PageContext clearEntityKeys() { | ||||||
|  |         return withEntityKey(null) | ||||||
|  |                 .withParentEntityKey(null); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean hasAttribute(final String name) { |     public boolean hasAttribute(final String name) { | ||||||
|         return this.attributes.containsKey(name); |         return this.attributes.containsKey(name); | ||||||
|  | @ -210,7 +209,6 @@ public class PageContextImpl implements PageContext { | ||||||
|         attrs.putAll(this.attributes); |         attrs.putAll(this.attributes); | ||||||
|         attrs.remove(name); |         attrs.remove(name); | ||||||
|         return new PageContextImpl( |         return new PageContextImpl( | ||||||
|                 this.restService, |  | ||||||
|                 this.i18nSupport, |                 this.i18nSupport, | ||||||
|                 this.composerService, |                 this.composerService, | ||||||
|                 this.root, |                 this.root, | ||||||
|  | @ -243,7 +241,7 @@ public class PageContextImpl implements PageContext { | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public Action createAction(final ActionDefinition actionDefinition) { |     public Action createAction(final ActionDefinition actionDefinition) { | ||||||
|         return new Action(actionDefinition, this, this.restService); |         return new Action(actionDefinition, this); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  |  | ||||||
|  | @ -74,6 +74,14 @@ public class CurrentUser { | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public GrantCheck grantCheck(final EntityType entityType) { | ||||||
|  |         return new GrantCheck(entityType); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public EntityGrantCheck entityGrantCheck(final GrantEntity grantEntity) { | ||||||
|  |         return new EntityGrantCheck(grantEntity); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public boolean hasBasePrivilege(final PrivilegeType privilegeType, final EntityType entityType) { |     public boolean hasBasePrivilege(final PrivilegeType privilegeType, final EntityType entityType) { | ||||||
|         return hasPrivilege(privilegeType, entityType, null, null); |         return hasPrivilege(privilegeType, entityType, null, null); | ||||||
|     } |     } | ||||||
|  | @ -206,4 +214,85 @@ public class CurrentUser { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** Wrapper can be used for base and institutional grant checks for a specified EntityType */ | ||||||
|  |     public class GrantCheck { | ||||||
|  |         private final EntityType entityType; | ||||||
|  | 
 | ||||||
|  |         protected GrantCheck(final EntityType entityType) { | ||||||
|  |             this.entityType = entityType; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the base read-only privilege grant | ||||||
|  |          *  | ||||||
|  |          * @return true on read-only privilege grant on wrapped EntityType */ | ||||||
|  |         public boolean r() { | ||||||
|  |             return hasBasePrivilege(PrivilegeType.READ_ONLY, this.entityType); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the base modify privilege grant | ||||||
|  |          *  | ||||||
|  |          * @return true on modify privilege grant on wrapped EntityType */ | ||||||
|  |         public boolean m() { | ||||||
|  |             return hasBasePrivilege(PrivilegeType.MODIFY, this.entityType); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the base write privilege grant | ||||||
|  |          *  | ||||||
|  |          * @return true on write privilege grant on wrapped EntityType */ | ||||||
|  |         public boolean w() { | ||||||
|  |             return hasBasePrivilege(PrivilegeType.WRITE, this.entityType); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the institutional read-only privilege grant | ||||||
|  |          *  | ||||||
|  |          * @return true institutional read-only privilege grant on wrapped EntityType */ | ||||||
|  |         public boolean ir() { | ||||||
|  |             return hasInstitutionalPrivilege(PrivilegeType.READ_ONLY, this.entityType); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the institutional modify privilege grant | ||||||
|  |          *  | ||||||
|  |          * @return true institutional modify privilege grant on wrapped EntityType */ | ||||||
|  |         public boolean im() { | ||||||
|  |             return hasInstitutionalPrivilege(PrivilegeType.MODIFY, this.entityType); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the institutional write privilege grant | ||||||
|  |          *  | ||||||
|  |          * @return true institutional write privilege grant on wrapped EntityType */ | ||||||
|  |         public boolean iw() { | ||||||
|  |             return hasInstitutionalPrivilege(PrivilegeType.WRITE, this.entityType); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** Wrapper can be used for Entity based grant checks */ | ||||||
|  |     public class EntityGrantCheck { | ||||||
|  |         private final GrantEntity grantEntity; | ||||||
|  | 
 | ||||||
|  |         protected EntityGrantCheck(final GrantEntity grantEntity) { | ||||||
|  |             this.grantEntity = grantEntity; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the read-only privilege grant for wrapped grantEntity | ||||||
|  |          *  | ||||||
|  |          * @return true on read-only privilege grant for wrapped grantEntity */ | ||||||
|  |         public boolean r() { | ||||||
|  |             return hasPrivilege(PrivilegeType.READ_ONLY, this.grantEntity); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the modify privilege grant for wrapped grantEntity | ||||||
|  |          *  | ||||||
|  |          * @return true on modify privilege grant for wrapped grantEntity */ | ||||||
|  |         public boolean m() { | ||||||
|  |             return hasPrivilege(PrivilegeType.MODIFY, this.grantEntity); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /** Checks the write privilege grant for wrapped grantEntity | ||||||
|  |          *  | ||||||
|  |          * @return true on write privilege grant for wrapped grantEntity */ | ||||||
|  |         public boolean w() { | ||||||
|  |             return hasPrivilege(PrivilegeType.WRITE, this.grantEntity); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.Constants; | import ch.ethz.seb.sebserver.gbl.Constants; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.Entity; | import ch.ethz.seb.sebserver.gbl.model.Entity; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.model.EntityKey; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.Page; | import ch.ethz.seb.sebserver.gbl.model.Page; | ||||||
| import ch.ethz.seb.sebserver.gbl.util.Utils; | import ch.ethz.seb.sebserver.gbl.util.Utils; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; | ||||||
|  | @ -174,7 +175,7 @@ public class EntityTable<ROW extends Entity> { | ||||||
|                 this.sortOrder); |                 this.sortOrder); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String getSingleSelection() { |     public EntityKey getSingleSelection() { | ||||||
|         final TableItem[] selection = this.table.getSelection(); |         final TableItem[] selection = this.table.getSelection(); | ||||||
|         if (selection == null || selection.length == 0) { |         if (selection == null || selection.length == 0) { | ||||||
|             return null; |             return null; | ||||||
|  | @ -183,7 +184,7 @@ public class EntityTable<ROW extends Entity> { | ||||||
|         return getRowDataId(selection[0]); |         return getRowDataId(selection[0]); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Set<String> getSelection() { |     public Set<EntityKey> getSelection() { | ||||||
|         final TableItem[] selection = this.table.getSelection(); |         final TableItem[] selection = this.table.getSelection(); | ||||||
|         if (selection == null) { |         if (selection == null) { | ||||||
|             return Collections.emptySet(); |             return Collections.emptySet(); | ||||||
|  | @ -348,8 +349,8 @@ public class EntityTable<ROW extends Entity> { | ||||||
|         return (ROW) item.getData(TABLE_ROW_DATA); |         return (ROW) item.getData(TABLE_ROW_DATA); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private String getRowDataId(final TableItem item) { |     private EntityKey getRowDataId(final TableItem item) { | ||||||
|         return getRowData(item).getModelId(); |         return getRowData(item).getEntityKey(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -38,7 +38,6 @@ public class TableBuilder<ROW extends Entity> { | ||||||
| 
 | 
 | ||||||
|     private final WidgetFactory widgetFactory; |     private final WidgetFactory widgetFactory; | ||||||
|     final RestCall<Page<ROW>> restCall; |     final RestCall<Page<ROW>> restCall; | ||||||
| //    final List<TableFilterAttribute> filter = new ArrayList<>(); |  | ||||||
|     final List<ColumnDefinition<ROW>> columns = new ArrayList<>(); |     final List<ColumnDefinition<ROW>> columns = new ArrayList<>(); | ||||||
|     final List<TableRowAction> actions = new ArrayList<>(); |     final List<TableRowAction> actions = new ArrayList<>(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,7 +14,6 @@ import java.io.InputStream; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Locale; | import java.util.Locale; | ||||||
| import java.util.function.Consumer; | import java.util.function.Consumer; | ||||||
| import java.util.function.Function; |  | ||||||
| import java.util.function.Supplier; | import java.util.function.Supplier; | ||||||
| 
 | 
 | ||||||
| import org.eclipse.rap.rwt.RWT; | import org.eclipse.rap.rwt.RWT; | ||||||
|  | @ -48,7 +47,6 @@ import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; | ||||||
| import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; | ||||||
| import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService; | import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.PageContext; | import ch.ethz.seb.sebserver.gui.service.page.PageContext; | ||||||
| import ch.ethz.seb.sebserver.gui.service.page.event.ActionEvent; |  | ||||||
| import ch.ethz.seb.sebserver.gui.service.push.ServerPushService; | import ch.ethz.seb.sebserver.gui.service.push.ServerPushService; | ||||||
| import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; | import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; | ||||||
| import ch.ethz.seb.sebserver.gui.table.TableBuilder; | import ch.ethz.seb.sebserver.gui.table.TableBuilder; | ||||||
|  | @ -155,16 +153,11 @@ public class WidgetFactory { | ||||||
|     public Composite defaultPageLayout( |     public Composite defaultPageLayout( | ||||||
|             final Composite parent, |             final Composite parent, | ||||||
|             final LocTextKey title, |             final LocTextKey title, | ||||||
|             final ActionDefinition actionDefinition, |             final ActionDefinition actionDefinition) { | ||||||
|             final Function<Label, Consumer<ActionEvent>> eventFunction) { |  | ||||||
| 
 | 
 | ||||||
|         final Composite defaultPageLayout = defaultPageLayout(parent); |         final Composite defaultPageLayout = defaultPageLayout(parent); | ||||||
|         final Label labelLocalizedTitle = labelLocalizedTitle(defaultPageLayout, title); |         final Label labelLocalizedTitle = labelLocalizedTitle(defaultPageLayout, title); | ||||||
|         labelLocalizedTitle.setLayoutData(new GridData(SWT.TOP, SWT.LEFT, true, false)); |         labelLocalizedTitle.setLayoutData(new GridData(SWT.TOP, SWT.LEFT, true, false)); | ||||||
| //        ActionEventListener.injectListener( |  | ||||||
| //                labelLocalizedTitle, |  | ||||||
| //                actionDefinition, |  | ||||||
| //                eventFunction.apply(labelLocalizedTitle)); |  | ||||||
|         return defaultPageLayout; |         return defaultPageLayout; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -88,7 +88,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
|     @RequestMapping( |     @RequestMapping( | ||||||
|             method = RequestMethod.GET, |             method = RequestMethod.GET, | ||||||
|             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public Page<T> getAll( |     public Page<T> getAll( | ||||||
|             @RequestParam( |             @RequestParam( | ||||||
|                     name = API.PARAM_INSTITUTION_ID, |                     name = API.PARAM_INSTITUTION_ID, | ||||||
|  | @ -126,7 +126,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
|             path = API.NAMES_PATH_SEGMENT, |             path = API.NAMES_PATH_SEGMENT, | ||||||
|             method = RequestMethod.GET, |             method = RequestMethod.GET, | ||||||
|             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public Collection<EntityName> getNames( |     public Collection<EntityName> getNames( | ||||||
|             @RequestParam( |             @RequestParam( | ||||||
|                     name = API.PARAM_INSTITUTION_ID, |                     name = API.PARAM_INSTITUTION_ID, | ||||||
|  | @ -160,7 +160,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
|             path = API.MODEL_ID_VAR_PATH_SEGMENT + API.DEPENDENCY_PATH_SEGMENT, |             path = API.MODEL_ID_VAR_PATH_SEGMENT + API.DEPENDENCY_PATH_SEGMENT, | ||||||
|             method = RequestMethod.GET, |             method = RequestMethod.GET, | ||||||
|             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public Collection<EntityKey> getDependencies( |     public Collection<EntityKey> getDependencies( | ||||||
|             @PathVariable final String modelId, |             @PathVariable final String modelId, | ||||||
|             @RequestParam(API.PARAM_BULK_ACTION_TYPE) final BulkActionType bulkActionType) { |             @RequestParam(API.PARAM_BULK_ACTION_TYPE) final BulkActionType bulkActionType) { | ||||||
|  | @ -186,7 +186,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
|             path = API.MODEL_ID_VAR_PATH_SEGMENT, |             path = API.MODEL_ID_VAR_PATH_SEGMENT, | ||||||
|             method = RequestMethod.GET, |             method = RequestMethod.GET, | ||||||
|             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public T getBy(@PathVariable final String modelId) { |     public T getBy(@PathVariable final String modelId) { | ||||||
| 
 | 
 | ||||||
|         return this.entityDAO |         return this.entityDAO | ||||||
|  | @ -203,7 +203,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
|             path = API.LIST_PATH_SEGMENT, |             path = API.LIST_PATH_SEGMENT, | ||||||
|             method = RequestMethod.GET, |             method = RequestMethod.GET, | ||||||
|             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public Collection<T> getForIds(@RequestParam(name = "ids", required = true) final String ids) { |     public Collection<T> getForIds(@RequestParam(name = "ids", required = true) final String ids) { | ||||||
| 
 | 
 | ||||||
|         return Result.tryCatch(() -> { |         return Result.tryCatch(() -> { | ||||||
|  | @ -228,7 +228,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
|     @RequestMapping( |     @RequestMapping( | ||||||
|             method = RequestMethod.POST, |             method = RequestMethod.POST, | ||||||
|             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |             consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public T create( |     public T create( | ||||||
|             @RequestParam final MultiValueMap<String, String> allRequestParams, |             @RequestParam final MultiValueMap<String, String> allRequestParams, | ||||||
|             @RequestParam( |             @RequestParam( | ||||||
|  | @ -261,8 +261,8 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
| 
 | 
 | ||||||
|     @RequestMapping( |     @RequestMapping( | ||||||
|             method = RequestMethod.PUT, |             method = RequestMethod.PUT, | ||||||
|             consumes = MediaType.APPLICATION_JSON_VALUE, |             consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public T savePut(@Valid @RequestBody final T modifyData) { |     public T savePut(@Valid @RequestBody final T modifyData) { | ||||||
| 
 | 
 | ||||||
|         return this.authorization.checkModify(modifyData) |         return this.authorization.checkModify(modifyData) | ||||||
|  | @ -309,7 +309,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt | ||||||
|     @RequestMapping( |     @RequestMapping( | ||||||
|             path = "/{modelId}", |             path = "/{modelId}", | ||||||
|             method = RequestMethod.DELETE, |             method = RequestMethod.DELETE, | ||||||
|             produces = MediaType.APPLICATION_JSON_VALUE) |             produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||||||
|     public EntityProcessingReport hardDelete(@PathVariable final String modelId) { |     public EntityProcessingReport hardDelete(@PathVariable final String modelId) { | ||||||
|         final EntityType entityType = this.entityDAO.entityType(); |         final EntityType entityType = this.entityDAO.entityType(); | ||||||
|         final BulkAction bulkAction = new BulkAction( |         final BulkAction bulkAction = new BulkAction( | ||||||
|  |  | ||||||
|  | @ -12,13 +12,19 @@ import static org.junit.Assert.assertEquals; | ||||||
| import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||||
| 
 | 
 | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
|  | import java.util.Arrays; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.stream.Collectors; | ||||||
| 
 | 
 | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.core.JsonParseException; | import com.fasterxml.jackson.core.JsonParseException; | ||||||
| import com.fasterxml.jackson.databind.JsonMappingException; | import com.fasterxml.jackson.databind.JsonMappingException; | ||||||
|  | import com.fasterxml.jackson.databind.ObjectWriter; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.api.JSONMapper; | import ch.ethz.seb.sebserver.gbl.api.JSONMapper; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.model.EntityName; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.model.Page; | ||||||
| 
 | 
 | ||||||
| public class InstitutionTest { | public class InstitutionTest { | ||||||
| 
 | 
 | ||||||
|  | @ -33,4 +39,60 @@ public class InstitutionTest { | ||||||
|         assertEquals("ETH Zürich", inst.name); |         assertEquals("ETH Zürich", inst.name); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Test | ||||||
|  |     public void pageOfInstituions() throws Exception { | ||||||
|  |         final Page<Institution> page = new Page<>(2, 1, "name", Arrays.asList( | ||||||
|  |                 new Institution(1L, "InstOne", "one", "", true), | ||||||
|  |                 new Institution(2L, "InstTwo", "two", "", true), | ||||||
|  |                 new Institution(3L, "InstThree", "three", "", true))); | ||||||
|  | 
 | ||||||
|  |         final JSONMapper jsonMapper = new JSONMapper(); | ||||||
|  |         final ObjectWriter writerWithDefaultPrettyPrinter = jsonMapper.writerWithDefaultPrettyPrinter(); | ||||||
|  |         String json = writerWithDefaultPrettyPrinter.writeValueAsString(page); | ||||||
|  |         assertEquals("{\r\n" + | ||||||
|  |                 "  \"number_of_pages\" : 2,\r\n" + | ||||||
|  |                 "  \"page_number\" : 1,\r\n" + | ||||||
|  |                 "  \"sort\" : \"name\",\r\n" + | ||||||
|  |                 "  \"content\" : [ {\r\n" + | ||||||
|  |                 "    \"id\" : 1,\r\n" + | ||||||
|  |                 "    \"name\" : \"InstOne\",\r\n" + | ||||||
|  |                 "    \"urlSuffix\" : \"one\",\r\n" + | ||||||
|  |                 "    \"logoImage\" : \"\",\r\n" + | ||||||
|  |                 "    \"active\" : true\r\n" + | ||||||
|  |                 "  }, {\r\n" + | ||||||
|  |                 "    \"id\" : 2,\r\n" + | ||||||
|  |                 "    \"name\" : \"InstTwo\",\r\n" + | ||||||
|  |                 "    \"urlSuffix\" : \"two\",\r\n" + | ||||||
|  |                 "    \"logoImage\" : \"\",\r\n" + | ||||||
|  |                 "    \"active\" : true\r\n" + | ||||||
|  |                 "  }, {\r\n" + | ||||||
|  |                 "    \"id\" : 3,\r\n" + | ||||||
|  |                 "    \"name\" : \"InstThree\",\r\n" + | ||||||
|  |                 "    \"urlSuffix\" : \"three\",\r\n" + | ||||||
|  |                 "    \"logoImage\" : \"\",\r\n" + | ||||||
|  |                 "    \"active\" : true\r\n" + | ||||||
|  |                 "  } ],\r\n" + | ||||||
|  |                 "  \"page_size\" : 3\r\n" + | ||||||
|  |                 "}", json); | ||||||
|  | 
 | ||||||
|  |         final List<EntityName> namesList = page.content.stream() | ||||||
|  |                 .map(inst -> new EntityName(inst.getEntityKey(), inst.name)) | ||||||
|  |                 .collect(Collectors.toList()); | ||||||
|  | 
 | ||||||
|  |         json = writerWithDefaultPrettyPrinter.writeValueAsString(namesList); | ||||||
|  |         assertEquals("[ {\r\n" + | ||||||
|  |                 "  \"entityType\" : \"INSTITUTION\",\r\n" + | ||||||
|  |                 "  \"modelId\" : \"1\",\r\n" + | ||||||
|  |                 "  \"name\" : \"InstOne\"\r\n" + | ||||||
|  |                 "}, {\r\n" + | ||||||
|  |                 "  \"entityType\" : \"INSTITUTION\",\r\n" + | ||||||
|  |                 "  \"modelId\" : \"2\",\r\n" + | ||||||
|  |                 "  \"name\" : \"InstTwo\"\r\n" + | ||||||
|  |                 "}, {\r\n" + | ||||||
|  |                 "  \"entityType\" : \"INSTITUTION\",\r\n" + | ||||||
|  |                 "  \"modelId\" : \"3\",\r\n" + | ||||||
|  |                 "  \"name\" : \"InstThree\"\r\n" + | ||||||
|  |                 "} ]", json); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 anhefti
						anhefti