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 String LIST_SEPARATOR = ","; | ||||
|     public static final String EMBEDDED_LIST_SEPARATOR = "|"; | ||||
|     public static final String EMPTY_NOTE = "--"; | ||||
|     public static final String FORM_URL_ENCODED_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.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; | ||||
| 
 | ||||
| public class POSTMapper { | ||||
|  | @ -151,6 +154,24 @@ public class POSTMapper { | |||
|         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") | ||||
|     public <T extends POSTMapper> T putIfAbsent(final String name, final String value) { | ||||
|         this.params.putIfAbsent(name, Arrays.asList(value)); | ||||
|  |  | |||
|  | @ -9,7 +9,6 @@ | |||
| package ch.ethz.seb.sebserver.gbl.model.exam; | ||||
| 
 | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | @ -93,7 +92,7 @@ public final class Indicator implements GrantEntity { | |||
|         this.name = postParams.getString(Domain.INDICATOR.ATTR_NAME); | ||||
|         this.type = postParams.getEnum(Domain.INDICATOR.ATTR_TYPE, IndicatorType.class); | ||||
|         this.defaultColor = postParams.getString(Domain.INDICATOR.ATTR_COLOR); | ||||
|         this.thresholds = Collections.emptyList(); | ||||
|         this.thresholds = postParams.getThresholds(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  |  | |||
|  | @ -251,7 +251,8 @@ public class ExamForm implements TemplateComposer { | |||
|             final EntityTable<Indicator> indicatorTable = | ||||
|                     this.pageService.entityTableBuilder(restService.getRestCall(GetIndicators.class)) | ||||
|                             .withEmptyMessage(new LocTextKey("sebserver.exam.indicator.list.empty")) | ||||
|                             .withPaging(3) | ||||
|                             .withPaging(5) | ||||
|                             .hideNavigation() | ||||
|                             .withColumn(new ColumnDefinition<>( | ||||
|                                     Domain.INDICATOR.ATTR_NAME, | ||||
|                                     nameColumnKey, | ||||
|  | @ -267,6 +268,10 @@ public class ExamForm implements TemplateComposer { | |||
|                                     thresholdColumnKey, | ||||
|                                     ExamForm::thresholdsValue, | ||||
|                                     false)) | ||||
|                             .withDefaultAction(actionBuilder | ||||
|                                     .newAction(ActionDefinition.EXAM_INDICATOR_MODIFY_FROM_LIST) | ||||
|                                     .withParentEntityKey(entityKey) | ||||
|                                     .create()) | ||||
| 
 | ||||
|                             .compose(content); | ||||
| 
 | ||||
|  |  | |||
|  | @ -104,7 +104,7 @@ public class IndicatorForm implements TemplateComposer { | |||
|                         indicator.getModelId()) | ||||
|                 .putStaticValue( | ||||
|                         Domain.EXAM.ATTR_INSTITUTION_ID, | ||||
|                         exam.getModelId()) | ||||
|                         String.valueOf(exam.getInstitutionId())) | ||||
|                 .putStaticValue( | ||||
|                         Domain.INDICATOR.ATTR_EXAM_ID, | ||||
|                         parentEntityKey.getModelId()) | ||||
|  |  | |||
|  | @ -270,10 +270,6 @@ public class ActivitiesPane implements TemplateComposer { | |||
| 
 | ||||
|         @Override | ||||
|         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 String modelId = (entityKey != null) ? entityKey.modelId : null; | ||||
|             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); | ||||
|         layout.horizontalSpacing = 10; | ||||
|         layout.verticalSpacing = 10; | ||||
|         layout.marginBottom = 50; | ||||
|         layout.marginLeft = 10; | ||||
|         layout.marginTop = 0; | ||||
|         this.formParent.setLayout(layout); | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ import org.eclipse.swt.layout.GridData; | |||
| import org.eclipse.swt.widgets.Label; | ||||
| 
 | ||||
| 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.gui.widget.ThresholdList; | ||||
| 
 | ||||
|  | @ -34,7 +35,8 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> { | |||
|     void build(final FormBuilder builder) { | ||||
|         final Label lab = builder.labelLocalized(builder.formParent, this.label, this.spanLabel); | ||||
|         if (builder.readonly || this.readonly) { | ||||
| 
 | ||||
|             // TODO do we need a read-only view for this? | ||||
|             return; | ||||
|         } else { | ||||
|             final ThresholdList thresholdList = builder.widgetFactory.thresholdList( | ||||
|                     builder.formParent, | ||||
|  | @ -53,8 +55,13 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> { | |||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         // thresholds={value}|{color},thresholds={value}|{color}... | ||||
|         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()), | ||||
|                 Constants.LIST_SEPARATOR); | ||||
|     } | ||||
|  |  | |||
|  | @ -180,9 +180,9 @@ public interface PageService { | |||
|             return this; | ||||
|         } | ||||
| 
 | ||||
|         public PageActionBuilder withSimpleRestCall( | ||||
|         public <T> PageActionBuilder withSimpleRestCall( | ||||
|                 final RestService restService, | ||||
|                 final Class<? extends RestCall<?>> restCallType) { | ||||
|                 final Class<? extends RestCall<T>> restCallType) { | ||||
| 
 | ||||
|             this.exec = action -> { | ||||
|                 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 PageAction action; | ||||
|     @Deprecated // use the ActionDefinition | ||||
|     public final boolean activity; | ||||
| 
 | ||||
|     public ActionEvent(final PageAction action) { | ||||
|         super(); | ||||
|         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); | ||||
| 
 | ||||
|             try { | ||||
|                 final OAuth2AccessToken accessToken = this.restTemplate.getAccessToken(); | ||||
|                 log.debug("Got token for user: {} : {}", username, "--"); | ||||
|                 this.restTemplate.getAccessToken(); | ||||
|                 log.debug("Got token for user: {}", username); | ||||
|                 this.loggedInUser = getLoggedInUser(); | ||||
|                 return true; | ||||
|             } catch (final OAuth2AccessDeniedException | AccessDeniedException e) { | ||||
|  |  | |||
|  | @ -82,7 +82,8 @@ public class EntityTable<ROW extends Entity> { | |||
|             final List<TableRowAction> actions, | ||||
|             final int pageSize, | ||||
|             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.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(); | ||||
|         updateTableRows( | ||||
|  | @ -287,7 +288,9 @@ public class EntityTable<ROW extends Entity> { | |||
|                 .withQueryParams((this.filter != null) ? this.filter.getFilterParameter() : null) | ||||
|                 .call() | ||||
|                 .map(this::createTableRowsFromPage) | ||||
|                 .map(this.navigator::update) | ||||
|                 .map(pageData -> (this.navigator != null) | ||||
|                         ? this.navigator.update(pageData) | ||||
|                         : pageData) | ||||
|                 .onErrorDo(t -> { | ||||
|                     // TODO error handling | ||||
|                 }); | ||||
|  | @ -357,8 +360,6 @@ public class EntityTable<ROW extends Entity> { | |||
|                     this.filter.adaptColumnWidth( | ||||
|                             this.table.indexOf(tableColumn), | ||||
|                             tableColumn.getWidth())) { | ||||
| 
 | ||||
|                 //this.composite.layout(true, true); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -48,6 +48,7 @@ public class TableBuilder<ROW extends Entity> { | |||
|     private Function<EntityTable<ROW>, PageAction> defaultActionFunction; | ||||
|     private int pageSize = -1; | ||||
|     private int type = SWT.NONE; | ||||
|     private boolean hideNavigation = false; | ||||
| 
 | ||||
|     public TableBuilder( | ||||
|             final PageService pageService, | ||||
|  | @ -57,6 +58,11 @@ public class TableBuilder<ROW extends Entity> { | |||
|         this.restCall = restCall; | ||||
|     } | ||||
| 
 | ||||
|     public TableBuilder<ROW> hideNavigation() { | ||||
|         this.hideNavigation = true; | ||||
|         return this; | ||||
|     } | ||||
| 
 | ||||
|     public TableBuilder<ROW> withEmptyMessage(final LocTextKey emptyMessage) { | ||||
|         this.emptyMessage = emptyMessage; | ||||
|         return this; | ||||
|  | @ -112,7 +118,8 @@ public class TableBuilder<ROW extends Entity> { | |||
|                 this.actions, | ||||
|                 this.pageSize, | ||||
|                 this.emptyMessage, | ||||
|                 this.defaultActionFunction); | ||||
|                 this.defaultActionFunction, | ||||
|                 this.hideNavigation); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -170,6 +170,17 @@ public class IndicatorDAOImpl implements IndicatorDAO { | |||
|                     modified.defaultColor); | ||||
| 
 | ||||
|             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; | ||||
|         }) | ||||
|                 .flatMap(this::toDomainModel) | ||||
|  |  | |||
|  | @ -111,7 +111,11 @@ public interface LmsAPIService { | |||
|                 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, | ||||
|                 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( | ||||
|                 (pageNumber != null) | ||||
|                         ? pageNumber | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 anhefti
						anhefti