fixed imports
This commit is contained in:
		
							parent
							
								
									12b4776b87
								
							
						
					
					
						commit
						33bd16d55a
					
				
					 3 changed files with 47 additions and 9 deletions
				
			
		|  | @ -154,6 +154,9 @@ public final class SebExamConfigImport { | ||||||
|                                     action.pageContext()); |                                     action.pageContext()); | ||||||
|                         } |                         } | ||||||
|                         return true; |                         return true; | ||||||
|  |                     } else { | ||||||
|  |                         formHandle.getContext().notifyError(configuration.getError()); | ||||||
|  |                         return true; | ||||||
|                     } |                     } | ||||||
|                 } else { |                 } else { | ||||||
|                     formHandle.getContext().publishPageMessage( |                     formHandle.getContext().publishPageMessage( | ||||||
|  |  | ||||||
|  | @ -296,6 +296,12 @@ public class ExamConfigImportHandler extends DefaultHandler { | ||||||
|             final String attrName, |             final String attrName, | ||||||
|             final ConfigurationAttribute attribute) { |             final ConfigurationAttribute attribute) { | ||||||
| 
 | 
 | ||||||
|  |         // no or blank value | ||||||
|  |         if (StringUtils.isBlank(top.value)) { | ||||||
|  |             saveValue(attrName, attribute, top.listIndex, null); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         final String[] names = StringUtils.split(top.valueName, Constants.LIST_SEPARATOR); |         final String[] names = StringUtils.split(top.valueName, Constants.LIST_SEPARATOR); | ||||||
|         final String[] values = StringUtils.split(top.value, Constants.LIST_SEPARATOR); |         final String[] values = StringUtils.split(top.value, Constants.LIST_SEPARATOR); | ||||||
|         final String[] columns = StringUtils.split(attribute.getResources(), Constants.EMBEDDED_LIST_SEPARATOR); |         final String[] columns = StringUtils.split(attribute.getResources(), Constants.EMBEDDED_LIST_SEPARATOR); | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ import java.io.BufferedInputStream; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
|  | import java.util.HashSet; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import javax.servlet.ServletOutputStream; | import javax.servlet.ServletOutputStream; | ||||||
|  | @ -21,6 +22,7 @@ import javax.validation.Valid; | ||||||
| 
 | 
 | ||||||
| import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||||
|  | import org.apache.commons.lang3.exception.ExceptionUtils; | ||||||
| import org.mybatis.dynamic.sql.SqlTable; | import org.mybatis.dynamic.sql.SqlTable; | ||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
|  | @ -38,10 +40,12 @@ import org.springframework.web.bind.annotation.RestController; | ||||||
| 
 | 
 | ||||||
| import ch.ethz.seb.sebserver.gbl.api.API; | import ch.ethz.seb.sebserver.gbl.api.API; | ||||||
| import ch.ethz.seb.sebserver.gbl.api.APIMessage; | import ch.ethz.seb.sebserver.gbl.api.APIMessage; | ||||||
|  | import ch.ethz.seb.sebserver.gbl.api.EntityType; | ||||||
| import ch.ethz.seb.sebserver.gbl.api.POSTMapper; | import ch.ethz.seb.sebserver.gbl.api.POSTMapper; | ||||||
| import ch.ethz.seb.sebserver.gbl.api.authorization.PrivilegeType; | import ch.ethz.seb.sebserver.gbl.api.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.EXAM; | import ch.ethz.seb.sebserver.gbl.model.Domain.EXAM; | ||||||
|  | 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.model.sebconfig.ConfigCopyInfo; | import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigCopyInfo; | ||||||
| import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigKey; | import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigKey; | ||||||
|  | @ -260,7 +264,22 @@ public class ConfigurationNodeController extends EntityController<ConfigurationN | ||||||
|                 .flatMap(this.configurationDAO::getFollowupConfiguration) |                 .flatMap(this.configurationDAO::getFollowupConfiguration) | ||||||
|                 .getOrThrow(); |                 .getOrThrow(); | ||||||
| 
 | 
 | ||||||
|         return doImport(password, request, followup); |         final Result<Configuration> doImport = doImport(password, request, followup); | ||||||
|  |         if (doImport.hasError()) { | ||||||
|  | 
 | ||||||
|  |             // rollback of the new configuration | ||||||
|  |             this.configurationNodeDAO.delete(new HashSet<>(Arrays.asList(new EntityKey( | ||||||
|  |                     followup.configurationNodeId, | ||||||
|  |                     EntityType.CONFIGURATION_NODE)))); | ||||||
|  | 
 | ||||||
|  |             final Throwable rootCause = ExceptionUtils.getRootCause(doImport.getError()); | ||||||
|  |             return new ResponseEntity<>( | ||||||
|  |                     Arrays.asList(APIMessage.ErrorMessage.UNEXPECTED.of(rootCause.getMessage())), | ||||||
|  |                     Utils.createJsonContentHeader(), | ||||||
|  |                     HttpStatus.BAD_REQUEST); | ||||||
|  |         } else { | ||||||
|  |             return doImport; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @RequestMapping( |     @RequestMapping( | ||||||
|  | @ -285,7 +304,19 @@ public class ConfigurationNodeController extends EntityController<ConfigurationN | ||||||
|                 .flatMap(this.configurationDAO::restoreToDefaultValues) |                 .flatMap(this.configurationDAO::restoreToDefaultValues) | ||||||
|                 .getOrThrow(); |                 .getOrThrow(); | ||||||
| 
 | 
 | ||||||
|         return doImport(password, request, newConfig); |         final Result<Configuration> doImport = doImport(password, request, newConfig); | ||||||
|  |         if (doImport.hasError()) { | ||||||
|  | 
 | ||||||
|  |             // rollback of the existing values | ||||||
|  |             this.configurationDAO.undo(newConfig.configurationNodeId); | ||||||
|  |             final Throwable rootCause = ExceptionUtils.getRootCause(doImport.getError()); | ||||||
|  |             return new ResponseEntity<>( | ||||||
|  |                     Arrays.asList(APIMessage.ErrorMessage.UNEXPECTED.of(rootCause.getMessage())), | ||||||
|  |                     Utils.createJsonContentHeader(), | ||||||
|  |                     HttpStatus.BAD_REQUEST); | ||||||
|  |         } else { | ||||||
|  |             return doImport; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @RequestMapping( |     @RequestMapping( | ||||||
|  | @ -474,30 +505,28 @@ public class ConfigurationNodeController extends EntityController<ConfigurationN | ||||||
|         return node; |         return node; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private Object doImport( |     private Result<Configuration> doImport( | ||||||
|             final String password, |             final String password, | ||||||
|             final HttpServletRequest request, |             final HttpServletRequest request, | ||||||
|             final Configuration configuration) throws IOException { |             final Configuration configuration) throws IOException { | ||||||
|         final InputStream inputStream = new BufferedInputStream(request.getInputStream()); |         final InputStream inputStream = new BufferedInputStream(request.getInputStream()); | ||||||
|         try { |         try { | ||||||
| 
 | 
 | ||||||
|             return this.sebExamConfigService.importFromSEBFile( |             final Configuration result = this.sebExamConfigService.importFromSEBFile( | ||||||
|                     configuration, |                     configuration, | ||||||
|                     inputStream, |                     inputStream, | ||||||
|                     password) |                     password) | ||||||
|                     .getOrThrow(); |                     .getOrThrow(); | ||||||
| 
 | 
 | ||||||
|  |             return Result.of(result); | ||||||
|  | 
 | ||||||
|         } catch (final Exception e) { |         } catch (final Exception e) { | ||||||
|             // NOTE: It seems that this has to be manually closed on error case |             // NOTE: It seems that this has to be manually closed on error case | ||||||
|             //       We expected that this is closed by the API but if this manual close is been left |             //       We expected that this is closed by the API but if this manual close is been left | ||||||
|             //       some left-overs will affect strange behavior. |             //       some left-overs will affect strange behavior. | ||||||
|             //       TODO: find a better solution for this |             //       TODO: find a better solution for this | ||||||
|             IOUtils.closeQuietly(inputStream); |             IOUtils.closeQuietly(inputStream); | ||||||
| 
 |             return Result.ofError(e); | ||||||
|             return new ResponseEntity<>( |  | ||||||
|                     Arrays.asList(APIMessage.ErrorMessage.UNEXPECTED.of(e.getMessage())), |  | ||||||
|                     Utils.createJsonContentHeader(), |  | ||||||
|                     HttpStatus.BAD_REQUEST); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 anhefti
						anhefti