diff --git a/CHANGELOG b/CHANGELOG index 1d02c5026166064a57887dda3e9322db397ef54a..6bfcc91cb308d5027703d573c1dc4826e896774b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,9 @@ minerva (14.0.0~alpha.0) unstable; urgency=low about type of database that identifies the target (#66) * Small improvement: redundant 'references' field in gene variants data overlay is now deprecated (#850) + * Small improvement: information about deprecated columns in data overlay is + visible in overlay list (#838) + * Small improvement: publication list is resizable (#740) * Bug fix: export to CellDesigner of reaction with two modifiers connected with boolean operator resulted was skipping some layout information * Bug fix: reaction in SBGNML file containing two products was improperly diff --git a/commons/src/main/java/lcsb/mapviewer/common/UnitTestFailedWatcher.java b/commons/src/main/java/lcsb/mapviewer/common/UnitTestFailedWatcher.java index cf8337839412ceb899d0adb94ed415855aaa1b53..833ee1a0c8d7b6a585345a8d66edfc4da0d14dff 100644 --- a/commons/src/main/java/lcsb/mapviewer/common/UnitTestFailedWatcher.java +++ b/commons/src/main/java/lcsb/mapviewer/common/UnitTestFailedWatcher.java @@ -6,6 +6,8 @@ import org.junit.runner.Description; public class UnitTestFailedWatcher extends TestWatcher { @Override protected void failed(Throwable e, Description description) { - e.printStackTrace(); + if (!(e instanceof AssertionError)) { + e.printStackTrace(); + } } } diff --git a/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js b/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js index e26912cc9434a9dbde7ba4d8dd3b6ef67312abc5..1c6454fa0405edb0fa5984c960cd024bd1b6f455 100644 --- a/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js +++ b/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js @@ -318,7 +318,17 @@ OverlayPanel.prototype.createOverlayRow = function (overlay, checked, disabled) OverlayPanel.prototype.overlayToDataRow = function (overlay, checked, disabled) { var result = []; result[0] = overlay.getOrder(); - result[1] = overlay.getName(); + if (overlay.getDeprecatedColumns() !== undefined && overlay.getDeprecatedColumns() !== null && overlay.getDeprecatedColumns().length > 0) { + + result[1] = "<div title='This data overlay uses old deprecated column names: "; + for (var j = 0; j < overlay.getDeprecatedColumns().length; j++) { + result[1] += overlay.getDeprecatedColumns()[j] + ", "; + } + result[1] += " This format will be not supported in minerva 15 and higher. Please re-upload data set using new format.'>" + + "<i class='fa fa-exclamation-triangle' style='font-size:18px; font-weight:400; padding-right:10px;color:orange'></i>" + overlay.getName() + "</div>" + } else { + result[1] = overlay.getName(); + } if (overlay.getInputDataAvailable()) { if (disabled) { @@ -351,6 +361,7 @@ OverlayPanel.prototype.overlayToDataRow = function (overlay, checked, disabled) "</div>"; } } + logger.debug(result); return result; }; diff --git a/frontend-js/src/main/js/map/data/DataOverlay.js b/frontend-js/src/main/js/map/data/DataOverlay.js index 16692fff0dbb5e6f1a90cb56f3ea5a3b044b3d96..8e5a78f53b94ebf74836b88f7a77a635f1b7790a 100644 --- a/frontend-js/src/main/js/map/data/DataOverlay.js +++ b/frontend-js/src/main/js/map/data/DataOverlay.js @@ -26,6 +26,7 @@ function DataOverlay(overlayId, name) { this.setImagesDirectory(object.images); this.setDescription(object.description); this.setCreator(object.creator); + this.setDeprecatedColumns(object.deprecatedColumns); this.setContent(object.content); this.setFilename(object.filename); this.setPublicOverlay(object.publicOverlay); @@ -328,6 +329,22 @@ DataOverlay.prototype.setContent = function (content) { this._content = content; }; +/** + * + * @returns {string[]} + */ +DataOverlay.prototype.getDeprecatedColumns = function () { + return this._deprecatedColumns; +}; + +/** + * + * @param {string[]} deprecatedColumns + */ +DataOverlay.prototype.setDeprecatedColumns = function (deprecatedColumns) { + this._deprecatedColumns = deprecatedColumns; +}; + /** * * @returns {number} @@ -380,7 +397,7 @@ DataOverlay.prototype.setType = function (type) { * * @param {boolean} value */ -DataOverlay.prototype.setGoogleLicenseConsent = function(value) { +DataOverlay.prototype.setGoogleLicenseConsent = function (value) { this._googleLicenseConsent = value; }; @@ -388,7 +405,7 @@ DataOverlay.prototype.setGoogleLicenseConsent = function(value) { * * @returns {boolean} */ -DataOverlay.prototype.isGoogleLicenseConsent = function() { +DataOverlay.prototype.isGoogleLicenseConsent = function () { return this._googleLicenseConsent; }; diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/BaseDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/BaseDao.java index 5cb391fb1974970566703b1586ba4ca568ecd532..efb3df7af91bfa2b7e796cf7f48152c1ef95a2ba 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/BaseDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/BaseDao.java @@ -254,7 +254,10 @@ public abstract class BaseDao<T> { * @return object width identifier given as parameter */ @SuppressWarnings("unchecked") - public T getById(int id) { + public T getById(Integer id) { + if (id == null) { + return null; + } List<?> list = getSession() .createQuery(" from " + this.clazz.getSimpleName() + " where id=:id " + removableAndStatemant()) .setParameter("id", id).list(); diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/map/ModelDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/map/ModelDao.java index 28b9f7f15f3cc0d3725a8d8358fc4def9e9ca655..395398d9c9e650577a6d2be4d9daa3fb380c888d 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/map/ModelDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/map/ModelDao.java @@ -40,12 +40,6 @@ public class ModelDao extends BaseDao<ModelData> { super.delete(model); } - @Override - public ModelData getById(int id) { - ModelData result = super.getById(id); - return result; - } - /** * Return the latest model for the project with a given project identifier. * diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java b/rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java index e5e295b8d406d27adc8bba98d38031cf10dcc726..b286c43cd408a9ccffd88694072ee7a0a57ae249 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/BaseController.java @@ -14,6 +14,7 @@ import org.springframework.web.HttpMediaTypeNotSupportedException; import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -42,7 +43,7 @@ public abstract class BaseController { || e instanceof HttpMessageNotReadableException || e instanceof MissingServletRequestParameterException || e instanceof HttpMediaTypeNotSupportedException - || e instanceof IllegalArgumentException) { + || e instanceof MethodArgumentTypeMismatchException) { logger.error(e, e); return createErrorResponse("Query server error.", e.getMessage(), new HttpHeaders(), HttpStatus.BAD_REQUEST); } else if (e instanceof ServletRequestBindingException && e.getMessage().contains(Configuration.AUTH_TOKEN)) { diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java index b7be8ff5af3f907c70abfda44200a1517faa4a37..bc9c4366ab4c056f74a422392e16135c94007e6c 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java @@ -8,6 +8,7 @@ import javax.xml.transform.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -160,10 +161,9 @@ public abstract class BaseRestImpl { * @param modelId * list of model identifiers separated by "," or '*' when all models * should be returned - * @throws ObjectNotFoundException - * thrown when data for given identifiers doesn't exist + * @throws QueryException */ - protected List<Model> getModels(String projectId, String modelId) throws ObjectNotFoundException { + protected List<Model> getModels(String projectId, String modelId) throws QueryException { Model model = modelService.getLastModelByProjectId(projectId); if (model == null) { throw new ObjectNotFoundException("Project with given id doesn't exist"); @@ -172,6 +172,10 @@ public abstract class BaseRestImpl { if (!modelId.equals("*")) { for (String str : modelId.split(",")) { + if (!StringUtils.isNumeric(str)) { + throw new QueryException("Invalid modelId: " + modelId); + } + Model submodel = model.getSubmodelById(Integer.valueOf(str)); if (submodel == null) { throw new ObjectNotFoundException("Model with given id doesn't exist"); diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/files/FileController.java b/rest-api/src/main/java/lcsb/mapviewer/api/files/FileController.java index fee30ce281e042109342bc2b5e499ee64b526373..1f9ec07f9e43010d8e225392da13766b4965a233 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/files/FileController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/files/FileController.java @@ -36,13 +36,13 @@ public class FileController extends BaseController { @PostAuthorize("hasAuthority('IS_ADMIN') or returnObject['owner'] == authentication.name") @GetMapping(value = "/{id}") - public Map<String, Object> getFile(@PathVariable(value = "id") String id) throws ObjectNotFoundException { + public Map<String, Object> getFile(@PathVariable(value = "id") Integer id) throws ObjectNotFoundException { return fileRest.getFile(id); } - @PreAuthorize("@fileService.getById(#id)?.owner?.login == authentication.name") + @PreAuthorize("@fileService.getOwnerByFileId(#id)?.login == authentication.name") @PostMapping(value = "/{id}:uploadContent") - public Map<String, Object> uploadContent(@PathVariable(value = "id") String id, @RequestBody byte[] data) + public Map<String, Object> uploadContent(@PathVariable(value = "id") Integer id, @RequestBody byte[] data) throws ObjectNotFoundException { return fileRest.uploadContent(id, data); } diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java index 636cf3c0052e0deb70260984a38a68d778c9292f..4a3073d7ef556c117e56b91af6a255b81f247dd9 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/files/FileRestImpl.java @@ -15,6 +15,7 @@ import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.model.cache.UploadedFileEntry; import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao; +import lcsb.mapviewer.services.interfaces.IFileService; @Transactional @Service @@ -22,9 +23,12 @@ public class FileRestImpl extends BaseRestImpl { private UploadedFileEntryDao uploadedFileEntryDao; + private IFileService fileService; + @Autowired - public FileRestImpl(UploadedFileEntryDao uploadedFileEntryDao) { + public FileRestImpl(UploadedFileEntryDao uploadedFileEntryDao, IFileService fileService) { this.uploadedFileEntryDao = uploadedFileEntryDao; + this.fileService = fileService; } public Map<String, Object> createFile(String filename, String length, User user) { @@ -35,15 +39,14 @@ public class FileRestImpl extends BaseRestImpl { entry.setOwner(user); uploadedFileEntryDao.add(entry); try { - return getFile(entry.getId() + ""); + return getFile(entry.getId()); } catch (ObjectNotFoundException e) { throw new InvalidStateException(e); } } - public Map<String, Object> getFile(String id) throws ObjectNotFoundException { - int fileId = Integer.valueOf(id); - UploadedFileEntry fileEntry = uploadedFileEntryDao.getById(fileId); + public Map<String, Object> getFile(Integer id) throws ObjectNotFoundException { + UploadedFileEntry fileEntry = fileService.getById(id); if (fileEntry == null) { throw new ObjectNotFoundException("Object not found"); } @@ -60,7 +63,7 @@ public class FileRestImpl extends BaseRestImpl { return result; } - public Map<String, Object> uploadContent(String id, byte[] data) throws ObjectNotFoundException { + public Map<String, Object> uploadContent(Integer id, byte[] data) throws ObjectNotFoundException { int fileId = Integer.valueOf(id); UploadedFileEntry fileEntry = uploadedFileEntryDao.getById(fileId); if (fileEntry == null) { diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/genomics/ReferenceGenomeRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/genomics/ReferenceGenomeRestImpl.java index d6271f6d2b3c8c0f3d8525cb353ab3bc38ce8367..b260d3c77451ead036cacdc3ff3f414890dc6cbf 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/genomics/ReferenceGenomeRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/genomics/ReferenceGenomeRestImpl.java @@ -168,7 +168,12 @@ public class ReferenceGenomeRestImpl extends BaseRestImpl { public List<Map<String, Object>> getReferenceGenomeVersions(String organismId, String type) throws QueryException { - ReferenceGenomeType genomeType = ReferenceGenomeType.valueOf(type); + ReferenceGenomeType genomeType = null; + try { + genomeType = ReferenceGenomeType.valueOf(type); + } catch (IllegalArgumentException e) { + throw new QueryException("Invalid type: " + type); + } MiriamData organism; if (organismId != null && !organismId.isEmpty()) { organism = new MiriamData(MiriamType.TAXONOMY, organismId); diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectController.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectController.java index 02801a3c10984232a66ebb95a8b300a25fe8c040..081f60fa2fed4333438e7879804b72d6b58e13aa 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectController.java @@ -114,7 +114,7 @@ public class ProjectController extends BaseController { @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @GetMapping(value = "/{projectId}/statistics") - public Object getStatistics(@PathVariable(value = "projectId") String projectId) throws ObjectNotFoundException { + public Object getStatistics(@PathVariable(value = "projectId") String projectId) throws QueryException { return projectController.getStatistics(projectId); } diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java index 00139e1e0fe870dc35b10fea34de4d13f8fa9fc8..63814e80e0d5efb9614d0b37a2ca57e89f2964d9 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java @@ -195,7 +195,7 @@ public class ProjectRestImpl extends BaseRestImpl { return project.getInputData(); } - public Map<String, Object> getStatistics(String projectId) throws ObjectNotFoundException { + public Map<String, Object> getStatistics(String projectId) throws QueryException { Map<String, Object> result = new TreeMap<>(); Map<MiriamType, Integer> elementAnnotations = new TreeMap<>(); @@ -624,7 +624,7 @@ public class ProjectRestImpl extends BaseRestImpl { return null; } - public List<Map<String, Object>> getSubmapConnections(String projectId) throws ObjectNotFoundException { + public List<Map<String, Object>> getSubmapConnections(String projectId) throws QueryException { List<Map<String, Object>> result = new ArrayList<>(); List<Model> models = getModels(projectId, "*"); List<Element> elements = new ArrayList<>(); diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelController.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelController.java index dabceafea3af823ae6c5984f035c131d67eedecc..de89361e932972474b2adc890549ed18a9e8e98e 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelController.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -37,7 +38,7 @@ public class ModelController extends BaseController { @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @GetMapping(value = "/") public List<Map<String, Object>> getModels(@PathVariable(value = "projectId") String projectId) - throws ObjectNotFoundException { + throws QueryException { return modelController.getModels(projectId); } @@ -45,7 +46,7 @@ public class ModelController extends BaseController { @GetMapping(value = "/{modelId:.+}") public Object getModel( @PathVariable(value = "modelId") String modelId, - @PathVariable(value = "projectId") String projectId) throws ObjectNotFoundException { + @PathVariable(value = "projectId") String projectId) throws QueryException { if (modelId.equals("*")) { return modelController.getModels(projectId); } else { diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java index 15c1affd90718d7568de167028890223a1d574bb..da7ac0174e87f935951793507aacaec67e4c6570 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java @@ -1,12 +1,12 @@ package lcsb.mapviewer.api.projects.models; -import java.awt.*; +import java.awt.Color; import java.awt.geom.*; import java.io.*; import java.util.*; -import java.util.List; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -59,7 +59,7 @@ public class ModelRestImpl extends BaseRestImpl { this.layoutService = layoutService; } - public List<Map<String, Object>> getModels(String projectId) throws ObjectNotFoundException { + public List<Map<String, Object>> getModels(String projectId) throws QueryException { Project project = getProjectService().getProjectByProjectId(projectId); if (project == null) { throw new ObjectNotFoundException("Project with given id doesn't exist"); @@ -67,7 +67,10 @@ public class ModelRestImpl extends BaseRestImpl { return createData(project); } - public Map<String, Object> getModel(String projectId, String modelId) { + public Map<String, Object> getModel(String projectId, String modelId) throws QueryException { + if (!StringUtils.isNumeric(modelId)) { + throw new QueryException("Invalid modelId: " + modelId); + } Model model = getModelService().getLastModelByProjectId(projectId); Model submodel = model.getSubmodelById(modelId); if (submodel == null) { @@ -95,7 +98,7 @@ public class ModelRestImpl extends BaseRestImpl { } } - private List<Map<String, Object>> createData(Project project) { + private List<Map<String, Object>> createData(Project project) throws QueryException { List<Map<String, Object>> result = new ArrayList<>(); Model model = getModelService().getLastModelByProjectId(project.getProjectId()); if (model != null) { diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImpl.java index 62ef329cc84489bfd77d5c4e9d982607f7518937..3e2c3fc1ba6c0d3897d2c11380c9b0d95b438f6f 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImpl.java @@ -36,7 +36,7 @@ public class ParametersRestImpl extends BaseRestImpl { } private Set<SbmlParameter> getParametersFromProject(String projectId, String modelId) - throws ObjectNotFoundException { + throws QueryException { List<Model> models = getModels(projectId, modelId); Set<SbmlParameter> parameters = new LinkedHashSet<>(); @@ -52,7 +52,7 @@ public class ParametersRestImpl extends BaseRestImpl { } private Set<SbmlParameter> getGlobalParametersFromProject(String projectId, String modelId) - throws ObjectNotFoundException { + throws QueryException { List<Model> models = getModels(projectId, modelId); Set<SbmlParameter> parameters = new LinkedHashSet<>(); diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/units/UnitsRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/units/UnitsRestImpl.java index b276f879574dd3a8bc6c3c86e052a2b172cb694a..692ba979125d30e03cf39f1ddeee3cf4dc40f5b9 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/units/UnitsRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/units/UnitsRestImpl.java @@ -59,7 +59,7 @@ public class UnitsRestImpl extends BaseRestImpl { return result; } - public List<Map<String, Object>> getUnits(String projectId, String modelId) throws ObjectNotFoundException { + public List<Map<String, Object>> getUnits(String projectId, String modelId) throws QueryException { List<Map<String, Object>> result = new ArrayList<>(); List<Model> models = getModels(projectId, modelId); for (Model model : models) { diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java index fd8a5c60442208682d3b13e20de5563bfcf47af8..3424a2acf83d4078a92eb0709d94a8f35f0042ea 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayController.java @@ -53,18 +53,18 @@ public class OverlayController extends BaseController { @GetMapping(value = "/{overlayId}/") public Map<String, Object> getOverlayById( @PathVariable(value = "projectId") String projectId, - @PathVariable(value = "overlayId") String overlayId) throws QueryException { + @PathVariable(value = "overlayId") Integer overlayId) throws QueryException { return overlayRestImp.getOverlayById(projectId, overlayId); } @PreAuthorize("hasAuthority('IS_ADMIN')" + " or hasAuthority('IS_CURATOR') and hasAuthority('READ_PROJECT:' + #projectId)" + " or hasAuthority('READ_PROJECT:' + #projectId) and " + - " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout)") + " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout == true)") @GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/") public List<Map<String, Object>> getOverlayElements( @PathVariable(value = "projectId") String projectId, - @PathVariable(value = "overlayId") String overlayId, + @PathVariable(value = "overlayId") Integer overlayId, @RequestParam(value = "columns", defaultValue = "") String columns) throws QueryException { return overlayRestImp.getOverlayElements(projectId, Integer.valueOf(overlayId), columns); } @@ -72,12 +72,12 @@ public class OverlayController extends BaseController { @PreAuthorize("hasAuthority('IS_ADMIN')" + " or hasAuthority('IS_CURATOR') and hasAuthority('READ_PROJECT:' + #projectId)" + " or hasAuthority('READ_PROJECT:' + #projectId) and " + - " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout)") + " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout == true)") @GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/reactions/{reactionId}/") public Map<String, Object> getFullReaction( @PathVariable(value = "projectId") String projectId, @PathVariable(value = "modelId") String modelId, - @PathVariable(value = "overlayId") String overlayId, + @PathVariable(value = "overlayId") Integer overlayId, @PathVariable(value = "reactionId") String reactionId, @RequestParam(value = "columns", defaultValue = "") String columns) throws QueryException, NumberFormatException, ObjectNotFoundException { @@ -88,12 +88,12 @@ public class OverlayController extends BaseController { @PreAuthorize("hasAuthority('IS_ADMIN')" + " or hasAuthority('IS_CURATOR') and hasAuthority('READ_PROJECT:' + #projectId)" + " or hasAuthority('READ_PROJECT:' + #projectId) and " + - " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout)") + " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout == true)") @GetMapping(value = "/{overlayId}/models/{modelId}/bioEntities/elements/{elementId}/") public Map<String, Object> getFullSpecies( @PathVariable(value = "projectId") String projectId, @PathVariable(value = "modelId") String modelId, - @PathVariable(value = "overlayId") String overlayId, + @PathVariable(value = "overlayId") Integer overlayId, @PathVariable(value = "elementId") String reactionId, @RequestParam(value = "columns", defaultValue = "") String columns) throws QueryException, NumberFormatException, ObjectNotFoundException { @@ -126,7 +126,7 @@ public class OverlayController extends BaseController { @DeleteMapping(value = "/{overlayId}") public Map<String, Object> removeOverlay( @PathVariable(value = "projectId") String projectId, - @PathVariable(value = "overlayId") String overlayId) throws QueryException, IOException { + @PathVariable(value = "overlayId") Integer overlayId) throws QueryException, IOException { return overlayRestImp.removeOverlay(projectId, overlayId); } @@ -136,7 +136,7 @@ public class OverlayController extends BaseController { @PatchMapping(value = "/{overlayId}") public Map<String, Object> updateOverlay( @RequestBody String body, - @PathVariable(value = "overlayId") String overlayId, + @PathVariable(value = "overlayId") Integer overlayId, @PathVariable(value = "projectId") String projectId) throws QueryException, IOException { Map<String, Object> node = parseBody(body); @@ -147,11 +147,11 @@ public class OverlayController extends BaseController { @PreAuthorize("hasAuthority('IS_ADMIN')" + " or hasAuthority('IS_CURATOR') and hasAuthority('READ_PROJECT:' + #projectId)" + " or hasAuthority('READ_PROJECT:' + #projectId) and " + - " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout)") + " (@layoutService.getLayoutById(#overlayId)?.creator?.login == authentication.name or @layoutService.getLayoutById(#overlayId)?.publicLayout == true)") @GetMapping(value = "/{overlayId}:downloadSource") public ResponseEntity<byte[]> getOverlaySource( @PathVariable(value = "projectId") String projectId, - @PathVariable(value = "overlayId") String overlayId) + @PathVariable(value = "overlayId") Integer overlayId) throws QueryException { FileEntry file = overlayRestImp.getOverlaySource(projectId, overlayId); diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java index 46a8341717d09bc3212dc5bb88f5c9794b2db865..ae80ae0dbec858b6ffad7cff299da78e0ab365a7 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java @@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import lcsb.mapviewer.api.*; import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.geometry.ColorParser; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.cache.FileEntry; @@ -26,6 +27,8 @@ import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao; import lcsb.mapviewer.persist.dao.map.LayoutDao; import lcsb.mapviewer.services.interfaces.ILayoutService; import lcsb.mapviewer.services.interfaces.ILayoutService.CreateLayoutParams; +import lcsb.mapviewer.services.utils.ColorSchemaReader; +import lcsb.mapviewer.services.utils.data.ColorSchemaColumn; @Transactional @Service @@ -78,6 +81,8 @@ public class OverlayRestImpl extends BaseRestImpl { result.put("description", overlay.getDescription()); result.put("publicOverlay", overlay.isPublicLayout()); result.put("defaultOverlay", overlay.isDefaultOverlay()); + + result.put("deprecatedColumns", getDeprecatedColumns(overlay)); result.put("googleLicenseConsent", overlay.isGoogleLicenseConsent()); List<Map<String, Object>> images = new ArrayList<>(); List<DataOverlayImageLayer> imageList = new ArrayList<>(overlay.getDataOverlayImageLayers()); @@ -97,6 +102,18 @@ public class OverlayRestImpl extends BaseRestImpl { return result; } + private List<String> getDeprecatedColumns(Layout overlay) { + try { + List<String> result = new ArrayList<>(); + for (ColorSchemaColumn column : new ColorSchemaReader().getDeprecatedColumns(overlay)) { + result.add(column.name()); + } + return result; + } catch (IOException | InvalidColorSchemaException e) { + throw new InvalidStateException(e); + } + } + public List<Map<String, Object>> getOverlayElements(String projectId, int overlayId, String columns) throws QueryException { @@ -130,28 +147,27 @@ public class OverlayRestImpl extends BaseRestImpl { return result; } - public Map<String, Object> getOverlayById(String projectId, String overlayId) + public Map<String, Object> getOverlayById(String projectId, Integer overlayId) throws QueryException { Model model = getModelService().getLastModelByProjectId(projectId); if (model == null) { throw new QueryException("Project with given id doesn't exist"); } - Layout overlay = layoutService.getLayoutById(Integer.valueOf(overlayId)); + Layout overlay = layoutService.getLayoutById(overlayId); if (overlay == null) { throw new QueryException("Overlay with given id doesn't exist"); } return overlayToMap(overlay); } - public FileEntry getOverlaySource(String projectId, String overlayId) + public FileEntry getOverlaySource(String projectId, Integer overlayId) throws QueryException { Model model = getModelService().getLastModelByProjectId(projectId); if (model == null) { throw new QueryException("Project with given id doesn't exist"); } try { - int id = Integer.parseInt(overlayId); - Layout layout = layoutService.getLayoutById(id); + Layout layout = layoutService.getLayoutById(overlayId); if (layout == null) { throw new QueryException("Invalid overlay id"); } @@ -163,13 +179,12 @@ public class OverlayRestImpl extends BaseRestImpl { } } - public Map<String, Object> updateOverlay(String overlayId, Map<String, Object> overlayData) throws QueryException { + public Map<String, Object> updateOverlay(Integer overlayId, Map<String, Object> overlayData) throws QueryException { if (overlayData == null) { throw new QueryException("overlay field cannot be undefined"); } try { - int id = Integer.parseInt(overlayId); - Layout layout = layoutService.getLayoutById(id); + Layout layout = layoutService.getLayoutById(overlayId); if (layout == null) { throw new ObjectNotFoundException("overlay doesn't exist"); } @@ -215,15 +230,14 @@ public class OverlayRestImpl extends BaseRestImpl { } } - public Map<String, Object> removeOverlay(String projectId, String overlayId) + public Map<String, Object> removeOverlay(String projectId, Integer overlayId) throws QueryException, IOException { Project project = getProjectService().getProjectByProjectId(projectId); if (project == null) { throw new ObjectNotFoundException("Project with given id doesn't exist"); } try { - int id = Integer.parseInt(overlayId); - Layout layout = layoutService.getLayoutById(id); + Layout layout = layoutService.getLayoutById(overlayId); if (layout == null) { throw new ObjectNotFoundException("Overlay doesn't exist"); } @@ -304,7 +318,7 @@ public class OverlayRestImpl extends BaseRestImpl { layout.setOrderIndex(count); layoutService.updateLayout(layout); - return getOverlayById(projectId, layout.getId() + ""); + return getOverlayById(projectId, layout.getId()); } catch (InvalidColorSchemaException e) { throw new QueryException(e.getMessage(), e); } diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/files/FileRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/files/FileRestImplTest.java index 413ae7eadb660df4c073eff071e7393933ec9c4c..1f2d50ba001ce90c172d6ed384284591a27a55b6 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/files/FileRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/files/FileRestImplTest.java @@ -46,14 +46,14 @@ public class FileRestImplTest extends RestTestFunctions { byte[] dataChunkMerged = ArrayUtils.addAll(dataChunk, dataChunk2); Map<String, Object> result = fileRestImpl.createFile("test.txt", "100", user); int id = (Integer) result.get("id"); - fileRestImpl.uploadContent(id + "", dataChunk); + fileRestImpl.uploadContent(id, dataChunk); UploadedFileEntry file = uploadedFileEntryDao.getById(id); assertEquals(100, file.getLength()); assertEquals(2, file.getFileContent().length); assertArrayEquals(dataChunk, file.getFileContent()); - fileRestImpl.uploadContent(id + "", dataChunk2); + fileRestImpl.uploadContent(id, dataChunk2); assertEquals(100, file.getLength()); assertEquals(4, file.getFileContent().length); @@ -70,7 +70,7 @@ public class FileRestImplTest extends RestTestFunctions { int id = (Integer) result.get("id"); try { - fileRestImpl.uploadContent(id + "", dataChunk); + fileRestImpl.uploadContent(id, dataChunk); } finally { uploadedFileEntryDao.getById(id); UploadedFileEntry file = uploadedFileEntryDao.getById(id); diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImplTest.java index 30a62541b25342a22fe932b48daca70eb8cdeba9..381443df7829a0613cfda89a50b47301fc392cd8 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/parameters/ParametersRestImplTest.java @@ -29,7 +29,7 @@ public class ParametersRestImplTest extends RestTestFunctions { @Test(expected = ObjectNotFoundException.class) public void testGetParameterForNonExistingModel() throws Exception { parametersRestImpl.getParameter(configurationService.getConfigurationValue(ConfigurationElementType.DEFAULT_MAP), - "-1", "-1"); + "0", "0"); } @Test(expected = ObjectNotFoundException.class) diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java index 40702e8a56aeed31cc903c4ea6cb4b80cb4f3b4f..3c7048d91b205db662e39f317932b96fe57fa8fc 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java @@ -66,7 +66,7 @@ public class OverlayRestImplTest extends RestTestFunctions { Map<String, Object> result = overlayRest.addOverlay(projectId, "x", "desc", "s1", null, null, ColorSchemaType.GENERIC.name(), "true", null); - String id = result.get("idObject").toString(); + Integer id = Integer.valueOf(result.get("idObject").toString()); Map<String, Object> data = new HashMap<>(); data.put("name", "xyz"); result = overlayRest.updateOverlay(id, data); @@ -84,7 +84,7 @@ public class OverlayRestImplTest extends RestTestFunctions { Map<String, Object> result = overlayRest.addOverlay(projectId, "x", "desc", "s1", null, null, ColorSchemaType.GENERIC.name(), "true", null); - String id = result.get("idObject").toString(); + Integer id = Integer.valueOf(result.get("idObject").toString()); Map<String, Object> data = new HashMap<>(); data.put("name", ""); result = overlayRest.updateOverlay(id, data); diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/FileService.java b/service/src/main/java/lcsb/mapviewer/services/impl/FileService.java index 8519510c35c0a55760b696ae1a770f01a5e0a4ab..0b94799a4caace195e693bbaebc813a767a6f7d8 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/FileService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/FileService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import lcsb.mapviewer.model.cache.UploadedFileEntry; +import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao; import lcsb.mapviewer.services.interfaces.IFileService; @@ -20,8 +21,22 @@ public class FileService implements IFileService { } @Override - public UploadedFileEntry getById(int id) { + public UploadedFileEntry getById(Integer id) { return uploadedFileEntryDao.getById(id); } + @Override + public User getOwnerByFileId(Integer id) { + if (id != null) { + UploadedFileEntry entry = uploadedFileEntryDao.getById(id); + if (entry != null && entry.getOwner() != null) { + // it's lazy initialized + entry.getOwner().getLogin(); + return uploadedFileEntryDao.getById(id).getOwner(); + } + } + return null; + + } + } diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java index 83cc8fe1e643cbe49bcc2de7f055a81ea3d90db1..ddd3c994722f02f817fb812fc1b3e830dc2252c6 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java @@ -469,7 +469,7 @@ public class LayoutService implements ILayoutService { } @Override - public Layout getLayoutById(int overlayId) { + public Layout getLayoutById(Integer overlayId) { return layoutDao.getById(overlayId); } diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/IFileService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/IFileService.java index 809e597a35499e154fe7cea52969afbb5fcb38b0..5598fecf5f4a68941dfef47bcf243d87923f22f4 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/IFileService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/IFileService.java @@ -1,9 +1,12 @@ package lcsb.mapviewer.services.interfaces; import lcsb.mapviewer.model.cache.UploadedFileEntry; +import lcsb.mapviewer.model.user.User; public interface IFileService { - UploadedFileEntry getById(int id); + UploadedFileEntry getById(Integer id); + + User getOwnerByFileId(Integer id); } diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java index 0e97cb53831797d75e81c2c96729f397504eff4a..a0da91ebeee5d4a7c66aaa5e200b65d7ad32970b 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java @@ -142,7 +142,7 @@ public interface ILayoutService { */ List<Layout> getLayoutsByProject(Project project); - Layout getLayoutById(int overlayId); + Layout getLayoutById(Integer overlayId); void setLayoutDao(LayoutDao layoutDao); diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java index 72200ad59433ef66f7304ebe0374a6fd890f01ba..2f5ba0faa2bdd1f03652d5844cbecdb91f837a07 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java @@ -1,10 +1,9 @@ package lcsb.mapviewer.services.utils; -import java.awt.*; +import java.awt.Color; import java.io.*; import java.lang.reflect.Field; import java.util.*; -import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -12,8 +11,7 @@ import org.apache.logging.log4j.Logger; import lcsb.mapviewer.annotation.services.MiriamConnector; import lcsb.mapviewer.common.*; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.common.exception.*; import lcsb.mapviewer.common.geometry.ColorParser; import lcsb.mapviewer.converter.model.celldesigner.species.SpeciesMapping; import lcsb.mapviewer.converter.zip.ZipEntryFileFactory; @@ -808,4 +806,36 @@ public class ColorSchemaReader { } return readColorSchema(new ByteArrayInputStream(inputData), params); } + + public List<ColorSchemaColumn> getDeprecatedColumns(Layout overlay) + throws IOException, InvalidColorSchemaException { + List<ColorSchemaColumn> result = new ArrayList<>(); + if (overlay.getInputData() != null) { + BufferedReader br = new BufferedReader( + new InputStreamReader(new ByteArrayInputStream(overlay.getInputData().getFileContent()))); + + String line = br.readLine(); + while (line != null && line.startsWith("#")) { + line = br.readLine(); + } + String[] columns = line.split("\t"); + if (columns.length > 1) { + + Map<ColorSchemaColumn, Integer> schemaColumns = new HashMap<>(); + parseColumns(columns, schemaColumns, ColorSchemaType.GENERIC); + for (ColorSchemaColumn column : schemaColumns.keySet()) { + try { + Field f = ColorSchemaColumn.class.getField(column.name()); + if (column.getDepractedColumnName() != null || f.isAnnotationPresent(Deprecated.class)) { + result.add(column); + } + } catch (NoSuchFieldException | SecurityException e) { + throw new InvalidStateException(e); + } + } + } + } + return result; + } + } diff --git a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java index 4592e44bb328023dae569574fde114b3be97c74f..f58cdd4923d1c5f3925ef44e0e9d83d14ae58f22 100644 --- a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java @@ -2,11 +2,10 @@ package lcsb.mapviewer.services.utils; import static org.junit.Assert.*; -import java.awt.*; +import java.awt.Color; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.*; -import java.util.List; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.logging.log4j.LogManager; @@ -16,6 +15,7 @@ import org.junit.*; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.commands.ColorModelCommand; import lcsb.mapviewer.common.TextFileUtils; +import lcsb.mapviewer.model.cache.UploadedFileEntry; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.layout.*; import lcsb.mapviewer.model.map.model.Model; @@ -326,4 +326,12 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { assertNotNull(schemas.iterator().next().getModelName()); } + @Test + public void testGetDeprecatedColumns() throws Exception { + Layout overlay = new Layout(); + UploadedFileEntry file = new UploadedFileEntry(); + file.setFileContent("blabla\nbasd\n".getBytes("UTF-8")); + overlay.setInputData(file); + assertEquals(0, reader.getDeprecatedColumns(overlay).size()); + } } diff --git a/web/src/test/java/lcsb/mapviewer/web/FileControllerIntegrationTestWithoutTransaction.java b/web/src/test/java/lcsb/mapviewer/web/FileControllerIntegrationTestWithoutTransaction.java index 9d32a6cf1823a50d5f2687d9a49c142179111352..2b351c9093e4289aa4957135d9351e0e52ac0d64 100644 --- a/web/src/test/java/lcsb/mapviewer/web/FileControllerIntegrationTestWithoutTransaction.java +++ b/web/src/test/java/lcsb/mapviewer/web/FileControllerIntegrationTestWithoutTransaction.java @@ -8,18 +8,23 @@ import java.util.Arrays; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpSession; -import org.springframework.test.annotation.Rollback; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.web.servlet.RequestBuilder; +import com.google.gson.JsonParser; + @RunWith(SpringJUnit4ClassRunner.class) -@Rollback public class FileControllerIntegrationTestWithoutTransaction extends ControllerIntegrationTest { + Logger logger = LogManager.getLogger(); + private static final String BUILT_IN_TEST_ADMIN_PASSWORD = "admin"; private static final String BUILT_IN_TEST_ADMIN_LOGIN = "admin"; @@ -42,4 +47,31 @@ public class FileControllerIntegrationTestWithoutTransaction extends ControllerI mockMvc.perform(request) .andExpect(status().is4xxClientError()); } + + @Test + public void createAndAppendToExistingFile() throws Exception { + MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD); + + String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList( + new BasicNameValuePair("filename", "unknown.txt"), + new BasicNameValuePair("length", "29")))); + + RequestBuilder request = post("/files/") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .content(body) + .session(session); + + String response = mockMvc.perform(request) + .andExpect(status().is2xxSuccessful()).andReturn().getResponse().getContentAsString(); + int id = new JsonParser().parse(response).getAsJsonObject().get("id").getAsInt(); + + String fileContent = "elementIdentifier\tvalue\nxx\t-1"; + + RequestBuilder postContentRequest = post("/files/" + id + ":uploadContent") + .content(fileContent) + .session(session); + + mockMvc.perform(postContentRequest) + .andExpect(status().is2xxSuccessful()); + } } diff --git a/web/src/test/java/lcsb/mapviewer/web/OverlayControllerIntegrationTest.java b/web/src/test/java/lcsb/mapviewer/web/OverlayControllerIntegrationTest.java index f0dfd1ee1fb168444710aa9b0a09b9b416afea58..5368aef970b0fad0e7eb22c766394e891b3ed355 100644 --- a/web/src/test/java/lcsb/mapviewer/web/OverlayControllerIntegrationTest.java +++ b/web/src/test/java/lcsb/mapviewer/web/OverlayControllerIntegrationTest.java @@ -34,6 +34,7 @@ import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.dao.map.LayoutDao; import lcsb.mapviewer.services.interfaces.IModelService; import lcsb.mapviewer.services.interfaces.IUserService; +import lcsb.mapviewer.services.utils.data.ColorSchemaColumn; @RunWith(SpringJUnit4ClassRunner.class) @Transactional @@ -422,9 +423,8 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest .getAsJsonArray().size()); } - private Layout createOverlay(User admin) { + private Layout createOverlay(User admin, String content) { UploadedFileEntry file = new UploadedFileEntry(); - String content = "elementIdentifier\tvalue\n\t-1"; file.setFileContent(content.getBytes()); file.setLength(content.getBytes().length); @@ -436,6 +436,10 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest return overlay; } + private Layout createOverlay(User admin) { + return createOverlay(admin, "elementIdentifier\tvalue\n\t-1"); + } + @Test public void testGetReactionsForOverlay() throws Exception { User admin = createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD); @@ -1028,4 +1032,30 @@ public class OverlayControllerIntegrationTest extends ControllerIntegrationTest .andExpect(status().is2xxSuccessful()); } + @Test + public void testDeprecatedOverlayInformation() throws Exception { + createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD); + + Layout overlay = createOverlay(null, + "elementIdentifier\t" + ColorSchemaColumn.REACTION_IDENTIFIER + "\tvalue\n\t\t-1"); + overlay.setPublicLayout(true); + layoutDao.update(overlay); + + MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD); + + RequestBuilder request = get( + "/projects/" + TEST_PROJECT + "/overlays/" + overlay.getId() + "/") + .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .session(session); + + String response = mockMvc.perform(request) + .andExpect(status().is2xxSuccessful()) + .andReturn().getResponse().getContentAsString(); + int deprecatedColumns = new JsonParser() + .parse(response) + .getAsJsonObject().get("deprecatedColumns").getAsJsonArray().size(); + + assertEquals(2, deprecatedColumns); + } + }