SEBSERV-30 minor fixes
This commit is contained in:
		
							parent
							
								
									6c27f2aeeb
								
							
						
					
					
						commit
						7940af0deb
					
				
					 16 changed files with 85 additions and 41 deletions
				
			
		|  | @ -24,6 +24,7 @@ public final class Constants { | ||||||
| 
 | 
 | ||||||
|     public static final Character LIST_SEPARATOR_CHAR = ','; |     public static final Character LIST_SEPARATOR_CHAR = ','; | ||||||
|     public static final String LIST_SEPARATOR = ","; |     public static final String LIST_SEPARATOR = ","; | ||||||
|  |     public static final String EMBEDDED_LIST_SEPARATOR = "|"; | ||||||
|     public static final String EMPTY_NOTE = "--"; |     public static final String EMPTY_NOTE = "--"; | ||||||
|     public static final String FORM_URL_ENCODED_SEPARATOR = "&"; |     public static final String FORM_URL_ENCODED_SEPARATOR = "&"; | ||||||
|     public static final String FORM_URL_ENCODED_NAME_VALUE_SEPARATOR = "="; |     public static final String FORM_URL_ENCODED_NAME_VALUE_SEPARATOR = "="; | ||||||
|  |  | ||||||
|  | @ -25,6 +25,9 @@ import org.joda.time.DateTimeZone; | ||||||
| import org.springframework.util.LinkedMultiValueMap; | import org.springframework.util.LinkedMultiValueMap; | ||||||
| import org.springframework.util.MultiValueMap; | import org.springframework.util.MultiValueMap; | ||||||
| 
 | 
 | ||||||
|  | import ch.ethz.seb.sebserver.gbl.Constants; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.model.Domain; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; | ||||||
| import ch.ethz.seb.sebserver.gbl.util.Utils; | import ch.ethz.seb.sebserver.gbl.util.Utils; | ||||||
| 
 | 
 | ||||||
| public class POSTMapper { | public class POSTMapper { | ||||||
|  | @ -151,6 +154,24 @@ public class POSTMapper { | ||||||
|         return Utils.toDateTime(value); |         return Utils.toDateTime(value); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public List<Threshold> getThresholds() { | ||||||
|  |         final List<String> thresholdStrings = this.params.get(Domain.THRESHOLD.REFERENCE_NAME); | ||||||
|  |         if (thresholdStrings == null || thresholdStrings.isEmpty()) { | ||||||
|  |             return Collections.emptyList(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return thresholdStrings.stream() | ||||||
|  |                 .map(ts -> { | ||||||
|  |                     try { | ||||||
|  |                         final String[] split = StringUtils.split(ts, Constants.EMBEDDED_LIST_SEPARATOR); | ||||||
|  |                         return new Threshold(Double.parseDouble(split[0]), split[1]); | ||||||
|  |                     } catch (final Exception e) { | ||||||
|  |                         return null; | ||||||
|  |                     } | ||||||
|  |                 }) | ||||||
|  |                 .collect(Collectors.toList()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @SuppressWarnings("unchecked") |     @SuppressWarnings("unchecked") | ||||||
|     public <T extends POSTMapper> T putIfAbsent(final String name, final String value) { |     public <T extends POSTMapper> T putIfAbsent(final String name, final String value) { | ||||||
|         this.params.putIfAbsent(name, Arrays.asList(value)); |         this.params.putIfAbsent(name, Arrays.asList(value)); | ||||||
|  |  | ||||||
|  | @ -9,7 +9,6 @@ | ||||||
| package ch.ethz.seb.sebserver.gbl.model.exam; | package ch.ethz.seb.sebserver.gbl.model.exam; | ||||||
| 
 | 
 | ||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
| import java.util.Collections; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import javax.validation.constraints.NotNull; | import javax.validation.constraints.NotNull; | ||||||
|  | @ -93,7 +92,7 @@ public final class Indicator implements GrantEntity { | ||||||
|         this.name = postParams.getString(Domain.INDICATOR.ATTR_NAME); |         this.name = postParams.getString(Domain.INDICATOR.ATTR_NAME); | ||||||
|         this.type = postParams.getEnum(Domain.INDICATOR.ATTR_TYPE, IndicatorType.class); |         this.type = postParams.getEnum(Domain.INDICATOR.ATTR_TYPE, IndicatorType.class); | ||||||
|         this.defaultColor = postParams.getString(Domain.INDICATOR.ATTR_COLOR); |         this.defaultColor = postParams.getString(Domain.INDICATOR.ATTR_COLOR); | ||||||
|         this.thresholds = Collections.emptyList(); |         this.thresholds = postParams.getThresholds(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  |  | ||||||
|  | @ -251,7 +251,8 @@ public class ExamForm implements TemplateComposer { | ||||||
|             final EntityTable<Indicator> indicatorTable = |             final EntityTable<Indicator> indicatorTable = | ||||||
|                     this.pageService.entityTableBuilder(restService.getRestCall(GetIndicators.class)) |                     this.pageService.entityTableBuilder(restService.getRestCall(GetIndicators.class)) | ||||||
|                             .withEmptyMessage(new LocTextKey("sebserver.exam.indicator.list.empty")) |                             .withEmptyMessage(new LocTextKey("sebserver.exam.indicator.list.empty")) | ||||||
|                             .withPaging(3) |                             .withPaging(5) | ||||||
|  |                             .hideNavigation() | ||||||
|                             .withColumn(new ColumnDefinition<>( |                             .withColumn(new ColumnDefinition<>( | ||||||
|                                     Domain.INDICATOR.ATTR_NAME, |                                     Domain.INDICATOR.ATTR_NAME, | ||||||
|                                     nameColumnKey, |                                     nameColumnKey, | ||||||
|  | @ -267,6 +268,10 @@ public class ExamForm implements TemplateComposer { | ||||||
|                                     thresholdColumnKey, |                                     thresholdColumnKey, | ||||||
|                                     ExamForm::thresholdsValue, |                                     ExamForm::thresholdsValue, | ||||||
|                                     false)) |                                     false)) | ||||||
|  |                             .withDefaultAction(actionBuilder | ||||||
|  |                                     .newAction(ActionDefinition.EXAM_INDICATOR_MODIFY_FROM_LIST) | ||||||
|  |                                     .withParentEntityKey(entityKey) | ||||||
|  |                                     .create()) | ||||||
| 
 | 
 | ||||||
|                             .compose(content); |                             .compose(content); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -104,7 +104,7 @@ public class IndicatorForm implements TemplateComposer { | ||||||
|                         indicator.getModelId()) |                         indicator.getModelId()) | ||||||
|                 .putStaticValue( |                 .putStaticValue( | ||||||
|                         Domain.EXAM.ATTR_INSTITUTION_ID, |                         Domain.EXAM.ATTR_INSTITUTION_ID, | ||||||
|                         exam.getModelId()) |                         String.valueOf(exam.getInstitutionId())) | ||||||
|                 .putStaticValue( |                 .putStaticValue( | ||||||
|                         Domain.INDICATOR.ATTR_EXAM_ID, |                         Domain.INDICATOR.ATTR_EXAM_ID, | ||||||
|                         parentEntityKey.getModelId()) |                         parentEntityKey.getModelId()) | ||||||
|  |  | ||||||
|  | @ -270,10 +270,6 @@ public class ActivitiesPane implements TemplateComposer { | ||||||
| 
 | 
 | ||||||
|         @Override |         @Override | ||||||
|         public void notify(final ActionEvent event) { |         public void notify(final ActionEvent event) { | ||||||
|             // TODO |  | ||||||
| //            final MainPageState mainPageState = MainPageState.get(); |  | ||||||
| //            mainPageState.action = event.action; |  | ||||||
|             if (!event.activity) { |  | ||||||
|             final EntityKey entityKey = event.action.getEntityKey(); |             final EntityKey entityKey = event.action.getEntityKey(); | ||||||
|             final String modelId = (entityKey != null) ? entityKey.modelId : null; |             final String modelId = (entityKey != null) ? entityKey.modelId : null; | ||||||
|             final TreeItem item = findItemByActionDefinition( |             final TreeItem item = findItemByActionDefinition( | ||||||
|  | @ -285,6 +281,5 @@ public class ActivitiesPane implements TemplateComposer { | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -65,6 +65,7 @@ public class FormBuilder { | ||||||
|         final GridLayout layout = new GridLayout(rows, true); |         final GridLayout layout = new GridLayout(rows, true); | ||||||
|         layout.horizontalSpacing = 10; |         layout.horizontalSpacing = 10; | ||||||
|         layout.verticalSpacing = 10; |         layout.verticalSpacing = 10; | ||||||
|  |         layout.marginBottom = 50; | ||||||
|         layout.marginLeft = 10; |         layout.marginLeft = 10; | ||||||
|         layout.marginTop = 0; |         layout.marginTop = 0; | ||||||
|         this.formParent.setLayout(layout); |         this.formParent.setLayout(layout); | ||||||
|  |  | ||||||
|  | @ -17,6 +17,7 @@ import org.eclipse.swt.layout.GridData; | ||||||
| import org.eclipse.swt.widgets.Label; | import org.eclipse.swt.widgets.Label; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.Constants; | import ch.ethz.seb.sebserver.gbl.Constants; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.model.Domain; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; | import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; | ||||||
| import ch.ethz.seb.sebserver.gui.widget.ThresholdList; | import ch.ethz.seb.sebserver.gui.widget.ThresholdList; | ||||||
| 
 | 
 | ||||||
|  | @ -34,7 +35,8 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> { | ||||||
|     void build(final FormBuilder builder) { |     void build(final FormBuilder builder) { | ||||||
|         final Label lab = builder.labelLocalized(builder.formParent, this.label, this.spanLabel); |         final Label lab = builder.labelLocalized(builder.formParent, this.label, this.spanLabel); | ||||||
|         if (builder.readonly || this.readonly) { |         if (builder.readonly || this.readonly) { | ||||||
| 
 |             // TODO do we need a read-only view for this? | ||||||
|  |             return; | ||||||
|         } else { |         } else { | ||||||
|             final ThresholdList thresholdList = builder.widgetFactory.thresholdList( |             final ThresholdList thresholdList = builder.widgetFactory.thresholdList( | ||||||
|                     builder.formParent, |                     builder.formParent, | ||||||
|  | @ -53,8 +55,13 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // thresholds={value}|{color},thresholds={value}|{color}... | ||||||
|         return StringUtils.join(thresholds.stream() |         return StringUtils.join(thresholds.stream() | ||||||
|                 .map(t -> String.valueOf(t.getValue()) + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR + t.getColor()) |                 .map(t -> Domain.THRESHOLD.REFERENCE_NAME | ||||||
|  |                         + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR | ||||||
|  |                         + String.valueOf(t.getValue()) | ||||||
|  |                         + Constants.EMBEDDED_LIST_SEPARATOR | ||||||
|  |                         + t.getColor()) | ||||||
|                 .collect(Collectors.toList()), |                 .collect(Collectors.toList()), | ||||||
|                 Constants.LIST_SEPARATOR); |                 Constants.LIST_SEPARATOR); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -180,9 +180,9 @@ public interface PageService { | ||||||
|             return this; |             return this; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public PageActionBuilder withSimpleRestCall( |         public <T> PageActionBuilder withSimpleRestCall( | ||||||
|                 final RestService restService, |                 final RestService restService, | ||||||
|                 final Class<? extends RestCall<?>> restCallType) { |                 final Class<? extends RestCall<T>> restCallType) { | ||||||
| 
 | 
 | ||||||
|             this.exec = action -> { |             this.exec = action -> { | ||||||
|                 restService.getBuilder(restCallType) |                 restService.getBuilder(restCallType) | ||||||
|  |  | ||||||
|  | @ -15,20 +15,10 @@ import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; | ||||||
| public final class ActionEvent implements PageEvent { | public final class ActionEvent implements PageEvent { | ||||||
| 
 | 
 | ||||||
|     public final PageAction action; |     public final PageAction action; | ||||||
|     @Deprecated // use the ActionDefinition |  | ||||||
|     public final boolean activity; |  | ||||||
| 
 | 
 | ||||||
|     public ActionEvent(final PageAction action) { |     public ActionEvent(final PageAction action) { | ||||||
|         super(); |         super(); | ||||||
|         this.action = action; |         this.action = action; | ||||||
|         this.activity = false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Deprecated |  | ||||||
|     public ActionEvent(final PageAction action, final boolean activity) { |  | ||||||
|         super(); |  | ||||||
|         this.action = action; |  | ||||||
|         this.activity = activity; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -205,8 +205,8 @@ public class OAuth2AuthorizationContextHolder implements AuthorizationContextHol | ||||||
|             log.debug("Trying to login for user: {}", username); |             log.debug("Trying to login for user: {}", username); | ||||||
| 
 | 
 | ||||||
|             try { |             try { | ||||||
|                 final OAuth2AccessToken accessToken = this.restTemplate.getAccessToken(); |                 this.restTemplate.getAccessToken(); | ||||||
|                 log.debug("Got token for user: {} : {}", username, "--"); |                 log.debug("Got token for user: {}", username); | ||||||
|                 this.loggedInUser = getLoggedInUser(); |                 this.loggedInUser = getLoggedInUser(); | ||||||
|                 return true; |                 return true; | ||||||
|             } catch (final OAuth2AccessDeniedException | AccessDeniedException e) { |             } catch (final OAuth2AccessDeniedException | AccessDeniedException e) { | ||||||
|  |  | ||||||
|  | @ -82,7 +82,8 @@ public class EntityTable<ROW extends Entity> { | ||||||
|             final List<TableRowAction> actions, |             final List<TableRowAction> actions, | ||||||
|             final int pageSize, |             final int pageSize, | ||||||
|             final LocTextKey emptyMessage, |             final LocTextKey emptyMessage, | ||||||
|             final Function<EntityTable<ROW>, PageAction> defaultActionFunction) { |             final Function<EntityTable<ROW>, PageAction> defaultActionFunction, | ||||||
|  |             final boolean hideNavigation) { | ||||||
| 
 | 
 | ||||||
|         this.composite = new Composite(parent, type); |         this.composite = new Composite(parent, type); | ||||||
|         this.pageService = pageService; |         this.pageService = pageService; | ||||||
|  | @ -143,7 +144,7 @@ public class EntityTable<ROW extends Entity> { | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.navigator = new TableNavigator(this); |         this.navigator = (hideNavigation) ? null : new TableNavigator(this); | ||||||
| 
 | 
 | ||||||
|         createTableColumns(); |         createTableColumns(); | ||||||
|         updateTableRows( |         updateTableRows( | ||||||
|  | @ -287,7 +288,9 @@ public class EntityTable<ROW extends Entity> { | ||||||
|                 .withQueryParams((this.filter != null) ? this.filter.getFilterParameter() : null) |                 .withQueryParams((this.filter != null) ? this.filter.getFilterParameter() : null) | ||||||
|                 .call() |                 .call() | ||||||
|                 .map(this::createTableRowsFromPage) |                 .map(this::createTableRowsFromPage) | ||||||
|                 .map(this.navigator::update) |                 .map(pageData -> (this.navigator != null) | ||||||
|  |                         ? this.navigator.update(pageData) | ||||||
|  |                         : pageData) | ||||||
|                 .onErrorDo(t -> { |                 .onErrorDo(t -> { | ||||||
|                     // TODO error handling |                     // TODO error handling | ||||||
|                 }); |                 }); | ||||||
|  | @ -357,8 +360,6 @@ public class EntityTable<ROW extends Entity> { | ||||||
|                     this.filter.adaptColumnWidth( |                     this.filter.adaptColumnWidth( | ||||||
|                             this.table.indexOf(tableColumn), |                             this.table.indexOf(tableColumn), | ||||||
|                             tableColumn.getWidth())) { |                             tableColumn.getWidth())) { | ||||||
| 
 |  | ||||||
|                 //this.composite.layout(true, true); |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -48,6 +48,7 @@ public class TableBuilder<ROW extends Entity> { | ||||||
|     private Function<EntityTable<ROW>, PageAction> defaultActionFunction; |     private Function<EntityTable<ROW>, PageAction> defaultActionFunction; | ||||||
|     private int pageSize = -1; |     private int pageSize = -1; | ||||||
|     private int type = SWT.NONE; |     private int type = SWT.NONE; | ||||||
|  |     private boolean hideNavigation = false; | ||||||
| 
 | 
 | ||||||
|     public TableBuilder( |     public TableBuilder( | ||||||
|             final PageService pageService, |             final PageService pageService, | ||||||
|  | @ -57,6 +58,11 @@ public class TableBuilder<ROW extends Entity> { | ||||||
|         this.restCall = restCall; |         this.restCall = restCall; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public TableBuilder<ROW> hideNavigation() { | ||||||
|  |         this.hideNavigation = true; | ||||||
|  |         return this; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public TableBuilder<ROW> withEmptyMessage(final LocTextKey emptyMessage) { |     public TableBuilder<ROW> withEmptyMessage(final LocTextKey emptyMessage) { | ||||||
|         this.emptyMessage = emptyMessage; |         this.emptyMessage = emptyMessage; | ||||||
|         return this; |         return this; | ||||||
|  | @ -112,7 +118,8 @@ public class TableBuilder<ROW extends Entity> { | ||||||
|                 this.actions, |                 this.actions, | ||||||
|                 this.pageSize, |                 this.pageSize, | ||||||
|                 this.emptyMessage, |                 this.emptyMessage, | ||||||
|                 this.defaultActionFunction); |                 this.defaultActionFunction, | ||||||
|  |                 this.hideNavigation); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -170,6 +170,17 @@ public class IndicatorDAOImpl implements IndicatorDAO { | ||||||
|                     modified.defaultColor); |                     modified.defaultColor); | ||||||
| 
 | 
 | ||||||
|             this.indicatorRecordMapper.insert(newRecord); |             this.indicatorRecordMapper.insert(newRecord); | ||||||
|  | 
 | ||||||
|  |             // insert thresholds | ||||||
|  |             modified.thresholds | ||||||
|  |                     .stream() | ||||||
|  |                     .map(threshold -> new ThresholdRecord( | ||||||
|  |                             null, | ||||||
|  |                             newRecord.getId(), | ||||||
|  |                             new BigDecimal(threshold.value), | ||||||
|  |                             threshold.color)) | ||||||
|  |                     .forEach(this.thresholdRecordMapper::insert); | ||||||
|  | 
 | ||||||
|             return newRecord; |             return newRecord; | ||||||
|         }) |         }) | ||||||
|                 .flatMap(this::toDomainModel) |                 .flatMap(this::toDomainModel) | ||||||
|  |  | ||||||
|  | @ -111,7 +111,11 @@ public interface LmsAPIService { | ||||||
|                 end = quizzes.size(); |                 end = quizzes.size(); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return new Page<>(quizzes.size() / pageSize, pageNumber, sortAttribute, quizzes.subList(start, end)); |             return new Page<>( | ||||||
|  |                     (quizzes.size() / pageSize) + 1, | ||||||
|  |                     pageNumber, | ||||||
|  |                     sortAttribute, | ||||||
|  |                     quizzes.subList(start, end)); | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -85,7 +85,9 @@ public class QuizImportController { | ||||||
|                 EntityType.EXAM, |                 EntityType.EXAM, | ||||||
|                 institutionId); |                 institutionId); | ||||||
| 
 | 
 | ||||||
|         final FilterMap filterMap = new FilterMap(allRequestParams); |         final FilterMap filterMap = new FilterMap(allRequestParams) | ||||||
|  |                 .putIfAbsent(Entity.FILTER_ATTR_INSTITUTION, String.valueOf(institutionId)); | ||||||
|  | 
 | ||||||
|         return this.lmsAPIService.requestQuizDataPage( |         return this.lmsAPIService.requestQuizDataPage( | ||||||
|                 (pageNumber != null) |                 (pageNumber != null) | ||||||
|                         ? pageNumber |                         ? pageNumber | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 anhefti
						anhefti