fixed instructions creation with attributes
This commit is contained in:
		
							parent
							
								
									f54b769388
								
							
						
					
					
						commit
						cea62d5fa4
					
				
					 4 changed files with 11 additions and 42 deletions
				
			
		| 
						 | 
					@ -324,7 +324,7 @@ public final class Result<T> {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static Result<Void> tryCatch(final Runnable runnable) {
 | 
					    public static Result<Void> tryCatch(final TryCatchRunnable runnable) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            runnable.run();
 | 
					            runnable.run();
 | 
				
			||||||
            return Result.EMPTY;
 | 
					            return Result.EMPTY;
 | 
				
			||||||
| 
						 | 
					@ -389,4 +389,8 @@ public final class Result<T> {
 | 
				
			||||||
        T get() throws Exception;
 | 
					        T get() throws Exception;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public interface TryCatchRunnable {
 | 
				
			||||||
 | 
					        void run() throws Exception;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -587,35 +587,6 @@ public final class Utils {
 | 
				
			||||||
        return (hexString.length() < 2) ? "0" + hexString : hexString;
 | 
					        return (hexString.length() < 2) ? "0" + hexString : hexString;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static String toJsonObject(final Map<String, String> attributes) {
 | 
					 | 
				
			||||||
        if (attributes == null || attributes.isEmpty()) {
 | 
					 | 
				
			||||||
            return StringUtils.EMPTY;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        final StringBuilder builder = attributes
 | 
					 | 
				
			||||||
                .entrySet()
 | 
					 | 
				
			||||||
                .stream()
 | 
					 | 
				
			||||||
                .reduce(
 | 
					 | 
				
			||||||
                        new StringBuilder(Constants.CURLY_BRACE_OPEN),
 | 
					 | 
				
			||||||
                        (sb, entry) -> sb
 | 
					 | 
				
			||||||
                                .append(Constants.DOUBLE_QUOTE)
 | 
					 | 
				
			||||||
                                .append(entry.getKey())
 | 
					 | 
				
			||||||
                                .append(Constants.DOUBLE_QUOTE)
 | 
					 | 
				
			||||||
                                .append(Constants.COLON)
 | 
					 | 
				
			||||||
                                .append(getJSONValue(entry.getValue()))
 | 
					 | 
				
			||||||
                                .append(Constants.COMMA),
 | 
					 | 
				
			||||||
                        StringBuilder::append)
 | 
					 | 
				
			||||||
                .append(Constants.CURLY_BRACE_CLOSE);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (builder.length() > 0) {
 | 
					 | 
				
			||||||
            return builder
 | 
					 | 
				
			||||||
                    .deleteCharAt(builder.length() - 1)
 | 
					 | 
				
			||||||
                    .toString();
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            return StringUtils.EMPTY;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static String getJSONValue(final String value) {
 | 
					    private static String getJSONValue(final String value) {
 | 
				
			||||||
        if (Constants.TRUE_STRING.equalsIgnoreCase(value) || Constants.FALSE_STRING.equalsIgnoreCase(value)) {
 | 
					        if (Constants.TRUE_STRING.equalsIgnoreCase(value) || Constants.FALSE_STRING.equalsIgnoreCase(value)) {
 | 
				
			||||||
            return value.toLowerCase();
 | 
					            return value.toLowerCase();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -262,7 +262,6 @@ public class MonitoringClientConnection implements TemplateComposer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            NOTIFICATION_LIST_NO_SELECTION_KEY)
 | 
					                            NOTIFICATION_LIST_NO_SELECTION_KEY)
 | 
				
			||||||
                    .noEventPropagation()
 | 
					                    .noEventPropagation()
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    .publishIf(() -> currentUser.get().hasRole(UserRole.EXAM_SUPPORTER), false);
 | 
					                    .publishIf(() -> currentUser.get().hasRole(UserRole.EXAM_SUPPORTER), false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _notificationTableSupplier = () -> notificationTable;
 | 
					            _notificationTableSupplier = () -> notificationTable;
 | 
				
			||||||
| 
						 | 
					@ -396,15 +395,6 @@ public class MonitoringClientConnection implements TemplateComposer {
 | 
				
			||||||
                            .publish();
 | 
					                            .publish();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//                actionBuilder
 | 
					 | 
				
			||||||
//                        .newAction(ActionDefinition.MONITOR_EXAM_CLIENT_CONNECTION_EXAM_ROOM_PROCTORING)
 | 
					 | 
				
			||||||
//                        .withEntityKey(parentEntityKey)
 | 
					 | 
				
			||||||
//                        .withExec(action -> this.monitoringProctoringService.openExamCollectionProctorScreen(
 | 
					 | 
				
			||||||
//                                action,
 | 
					 | 
				
			||||||
//                                connectionData))
 | 
					 | 
				
			||||||
//                        .noEventPropagation()
 | 
					 | 
				
			||||||
//                        .publish();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                clientConnectionDetails.setStatusChangeListener(ccd -> {
 | 
					                clientConnectionDetails.setStatusChangeListener(ccd -> {
 | 
				
			||||||
                    this.pageService.firePageEvent(
 | 
					                    this.pageService.firePageEvent(
 | 
				
			||||||
                            new ActionActivationEvent(
 | 
					                            new ActionActivationEvent(
 | 
				
			||||||
| 
						 | 
					@ -426,6 +416,11 @@ public class MonitoringClientConnection implements TemplateComposer {
 | 
				
			||||||
        final EntityKey entityKey = table.getSingleSelection();
 | 
					        final EntityKey entityKey = table.getSingleSelection();
 | 
				
			||||||
        final EntityKey parentEntityKey = pageAction.getParentEntityKey();
 | 
					        final EntityKey parentEntityKey = pageAction.getParentEntityKey();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (entityKey == null) {
 | 
				
			||||||
 | 
					            pageAction.pageContext().publishInfo(NOTIFICATION_LIST_NO_SELECTION_KEY);
 | 
				
			||||||
 | 
					            return pageAction;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.pageService.getRestService()
 | 
					        this.pageService.getRestService()
 | 
				
			||||||
                .getBuilder(ConfirmPendingClientNotification.class)
 | 
					                .getBuilder(ConfirmPendingClientNotification.class)
 | 
				
			||||||
                .withURIVariable(API.PARAM_PARENT_MODEL_ID, parentEntityKey.modelId)
 | 
					                .withURIVariable(API.PARAM_PARENT_MODEL_ID, parentEntityKey.modelId)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,6 @@ import ch.ethz.seb.sebserver.gbl.model.session.ClientInstruction.InstructionType
 | 
				
			||||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
 | 
					import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
 | 
				
			||||||
import ch.ethz.seb.sebserver.gbl.util.Result;
 | 
					import ch.ethz.seb.sebserver.gbl.util.Result;
 | 
				
			||||||
import ch.ethz.seb.sebserver.gbl.util.SizedArrayNonBlockingQueue;
 | 
					import ch.ethz.seb.sebserver.gbl.util.SizedArrayNonBlockingQueue;
 | 
				
			||||||
import ch.ethz.seb.sebserver.gbl.util.Utils;
 | 
					 | 
				
			||||||
import ch.ethz.seb.sebserver.webservice.WebserviceInfo;
 | 
					import ch.ethz.seb.sebserver.webservice.WebserviceInfo;
 | 
				
			||||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientInstructionRecord;
 | 
					import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientInstructionRecord;
 | 
				
			||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ClientConnectionDAO;
 | 
					import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ClientConnectionDAO;
 | 
				
			||||||
| 
						 | 
					@ -143,7 +142,7 @@ public class SEBClientInstructionServiceImpl implements SEBClientInstructionServ
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return Result.tryCatch(() -> {
 | 
					        return Result.tryCatch(() -> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            final String attributesString = Utils.toJsonObject(attributes);
 | 
					            final String attributesString = this.jsonMapper.writeValueAsString(attributes);
 | 
				
			||||||
            final Set<String> activeConnections = this.clientConnectionDAO
 | 
					            final Set<String> activeConnections = this.clientConnectionDAO
 | 
				
			||||||
                    .filterForInstructionStatus(examId, connectionTokens)
 | 
					                    .filterForInstructionStatus(examId, connectionTokens)
 | 
				
			||||||
                    .getOrElse(Collections::emptySet);
 | 
					                    .getOrElse(Collections::emptySet);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue