diff --git a/.gitignore b/.gitignore index c84448e5b12c639424b7cb9f121fe45b127cca8f..e6be5bf7501679cf12b9e1c4adc06b23e372e38a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,7 @@ src/generated gradle.properties /out /build -dependencies.txt -/webapps -/bin/ +/bin .classpath .project .settings/ diff --git a/build.gradle b/build.gradle index b4a5e48469a209a703e0bf7fa0c6d9efb094ec8a..2e3efa7c6772f8a3c2d074fd0bdc1ab303023f74 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ def vXnat = '1.7.0-SNAPSHOT' def vXnatPipeline = vXnat -def vSpring = '4.2.4.RELEASE' -def vSpringSecurity = '4.0.3.RELEASE' +def vSpring = '4.2.5.RELEASE' +def vSpringSecurity = '4.0.4.RELEASE' def vSwagger = '2.3.1' def vHibernate = '4.3.11.Final' def vEhcache = '2.6.11' @@ -34,19 +34,16 @@ buildscript { jcenter() } dependencies { - classpath "org.nrg.xnat.build:gradle-xnat-plugin:1.7.0-SNAPSHOT" classpath "com.bmuschko:gradle-cargo-plugin:2.2.2" classpath "com.bmuschko:gradle-tomcat-plugin:2.2.4" } } -apply plugin: 'xnat' apply plugin: 'groovy' apply plugin: 'java' apply plugin: 'war' apply plugin: 'maven' apply plugin: 'maven-publish' -apply plugin: 'ivy-publish' apply plugin: 'com.bmuschko.tomcat' apply plugin: 'com.bmuschko.cargo' apply plugin: 'idea' @@ -238,6 +235,9 @@ configurations { dependencies { // NRG dependencies first. compile "org.nrg.xnat:spawner:${vXnat}" + compile("org.nrg.xnat:xnat-data-models:${vXnat}"){ + transitive = false + } compile "org.nrg.xdat:core:${vXnat}" compile "org.nrg:framework:${vXnat}" compile "org.nrg:transaction:${vXnat}" @@ -248,9 +248,6 @@ dependencies { compile "org.nrg:anonymize:${vXnat}" compile "org.nrg:mail:${vXnat}" compile "org.nrg:notify:${vXnat}" - compile("org.nrg.xnat:xnat-data-plugin:${vXnat}"){ - transitive = false - } compile "org.nrg:dicom-xnat-mx:1.7.0-SNAPSHOT" compile "org.nrg:dicom-xnat-sop:1.7.0-SNAPSHOT" diff --git a/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java b/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java index 2abf2d607eb0254d12e5bd144ff808cdc05102a6..deea66e3e5f31938f58654b7ea812e3608f362fd 100644 --- a/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java +++ b/src/main/java/org/nrg/xapi/rest/theme/ThemeApi.java @@ -1,5 +1,4 @@ /* - * org.nrg.xnat.turbine.modules.screens.ManageProtocol * XNAT http://www.xnat.org * Copyright (c) 2013, Washington University School of Medicine * All Rights Reserved @@ -16,10 +15,10 @@ import io.swagger.annotations.*; import org.apache.commons.io.FileUtils; import org.nrg.framework.annotations.XapiRestController; import org.nrg.xapi.rest.NotFoundException; +import org.nrg.xdat.entities.ThemeConfig; import org.nrg.xdat.security.XDATUser; import org.nrg.xft.security.UserI; -import org.nrg.xnat.configuration.ThemeConfig; -import org.nrg.xnat.services.ThemeService; +import org.nrg.xdat.services.ThemeService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/org/nrg/xnat/configuration/SerializerConfig.java b/src/main/java/org/nrg/xnat/configuration/SerializerConfig.java index f4702c9e57e2c3e2f71ac2d2ffc3ab16919d54f8..3871859ede4960d66ad820fd82a28217b4c10d78 100644 --- a/src/main/java/org/nrg/xnat/configuration/SerializerConfig.java +++ b/src/main/java/org/nrg/xnat/configuration/SerializerConfig.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.jetbrains.annotations.NotNull; -import org.nrg.xnat.utils.SerializerService; +import org.nrg.framework.services.SerializerService; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/org/nrg/xnat/configuration/ThemeConfig.java b/src/main/java/org/nrg/xnat/configuration/ThemeConfig.java deleted file mode 100644 index ca054e8cd1c35cd3dde953c0ddb2d50f01d222e2..0000000000000000000000000000000000000000 --- a/src/main/java/org/nrg/xnat/configuration/ThemeConfig.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * org.nrg.xnat.turbine.modules.screens.ManageProtocol - * XNAT http://www.xnat.org - * Copyright (c) 2013, Washington University School of Medicine - * All Rights Reserved - * - * Released under the Simplified BSD. - * - * Author: Justin Cleveland <clevelandj@wustl.edu> - * Last modified 2/8/2016 11:29 AM - */ - -package org.nrg.xnat.configuration; - -import java.util.ArrayList; - -/** - * Created by jcleve01 on 2/8/2016. - */ -public class ThemeConfig { - private String name = null; - private String path = null; - private boolean enabled = true; - private ArrayList roles = new ArrayList(); - - /** - * Dummy constructor to make Jackson mapper happy. Don't explictly use this. - */ - public ThemeConfig() { - } - public ThemeConfig(String themeName, String themePath, boolean enabled) { - this.name = themeName; - this.path = themePath; - this.enabled = enabled; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public ArrayList getRoles() { - return roles; - } - - public void setRoles(ArrayList roles) { - this.roles = roles; - } -} diff --git a/src/main/java/org/nrg/xnat/event/listeners/PipelineEmailHandlerAbst.java b/src/main/java/org/nrg/xnat/event/listeners/PipelineEmailHandlerAbst.java index 2a6ef18fc1091e54c4eb415de4f7a5209547ec31..30690dbe06bfbd07dd4586d768681d359639e023 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/PipelineEmailHandlerAbst.java +++ b/src/main/java/org/nrg/xnat/event/listeners/PipelineEmailHandlerAbst.java @@ -6,6 +6,7 @@ import com.google.common.collect.Maps; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.xmlbeans.XmlException; +import org.nrg.framework.services.SerializerService; import org.nrg.pipeline.xmlbeans.AllResolvedStepsDocument; import org.nrg.pipeline.xmlbeans.ParameterData; import org.nrg.xdat.XDAT; @@ -19,7 +20,6 @@ import org.nrg.xdat.turbine.utils.TurbineUtils; import org.nrg.xft.db.PoolDBUtils; import org.nrg.xft.event.WorkflowStatusEvent; import org.nrg.xnat.notifications.NotifyProjectPipelineListeners; -import org.nrg.xnat.utils.SerializerService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java b/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java index 859f28587350d4c2550d58e74244d2650e2cf44a..d24fc998c91f0adb9b095dc615647eacf16f0cb3 100644 --- a/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java +++ b/src/main/java/org/nrg/xnat/helpers/prearchive/PrearcDatabase.java @@ -10,7 +10,6 @@ */ package org.nrg.xnat.helpers.prearchive; -import com.fasterxml.jackson.core.JsonFactory; import com.google.common.base.Strings; import com.google.common.collect.Maps; import org.apache.commons.collections.CollectionUtils; @@ -21,6 +20,7 @@ import org.nrg.automation.services.ScriptService; import org.nrg.dicomtools.filters.DicomFilterService; import org.nrg.dicomtools.filters.SeriesImportFilter; import org.nrg.framework.constants.PrearchiveCode; +import org.nrg.framework.services.SerializerService; import org.nrg.status.ListenerUtils; import org.nrg.status.StatusListenerI; import org.nrg.xdat.XDAT; @@ -41,7 +41,7 @@ import org.nrg.xnat.restlet.XNATApplication; import org.nrg.xnat.restlet.actions.PrearcImporterA.PrearcSession; import org.nrg.xnat.restlet.services.Archiver; import org.nrg.xnat.turbine.utils.ArcSpecManager; -import org.nrg.xnat.utils.SerializerService; + import org.nrg.xnat.utils.XnatUserProvider; import org.restlet.data.Status; import org.slf4j.Logger; diff --git a/src/main/java/org/nrg/xnat/restlet/resources/SecureResource.java b/src/main/java/org/nrg/xnat/restlet/resources/SecureResource.java index 45c58132afefd1cf312754b05fd2e1a1a9abcdca..8b63e41ebdf63a6e44196954e3eef86e357340bd 100644 --- a/src/main/java/org/nrg/xnat/restlet/resources/SecureResource.java +++ b/src/main/java/org/nrg/xnat/restlet/resources/SecureResource.java @@ -66,7 +66,7 @@ import org.nrg.xnat.restlet.representations.*; import org.nrg.xnat.restlet.util.FileWriterWrapperI; import org.nrg.xnat.restlet.util.RequestUtil; import org.nrg.xnat.turbine.utils.ArchivableItem; -import org.nrg.xnat.utils.SerializerService; +import org.nrg.framework.services.SerializerService; import org.nrg.xnat.utils.WorkflowUtils; import org.restlet.Context; import org.restlet.data.*; diff --git a/src/main/java/org/nrg/xnat/restlet/services/AliasTokenRestlet.java b/src/main/java/org/nrg/xnat/restlet/services/AliasTokenRestlet.java index c7c6b2ce4da3c1417c564d0ffbd217f9e2cf0d69..e73a29c357afcfa2408c6c642e294ebd2e0b435c 100644 --- a/src/main/java/org/nrg/xnat/restlet/services/AliasTokenRestlet.java +++ b/src/main/java/org/nrg/xnat/restlet/services/AliasTokenRestlet.java @@ -17,7 +17,7 @@ import org.nrg.xdat.entities.AliasToken; import org.nrg.xdat.security.helpers.Roles; import org.nrg.xdat.services.AliasTokenService; import org.nrg.xnat.restlet.resources.SecureResource; -import org.nrg.xnat.utils.SerializerService; +import org.nrg.framework.services.SerializerService; import org.restlet.Context; import org.restlet.data.MediaType; import org.restlet.data.Request; diff --git a/src/main/java/org/nrg/xnat/services/ThemeService.java b/src/main/java/org/nrg/xnat/services/ThemeService.java deleted file mode 100644 index 47b61271374a434602fb88d3eb13fed31499cae5..0000000000000000000000000000000000000000 --- a/src/main/java/org/nrg/xnat/services/ThemeService.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * org.nrg.xnat.turbine.modules.screens.ManageProtocol - * XNAT http://www.xnat.org - * Copyright (c) 2013, Washington University School of Medicine - * All Rights Reserved - * - * Released under the Simplified BSD. - * - * Author: Justin Cleveland <clevelandj@wustl.edu> (jcleve01) - * Last modified 2/29/2016 11:20 AM - */ -package org.nrg.xnat.services; - -import org.jetbrains.annotations.NotNull; -import org.nrg.xnat.configuration.ThemeConfig; -import org.springframework.stereotype.Service; - -import java.io.*; -import java.util.List; - -@Service -public interface ThemeService { - -// abstract public void postServiceConstruction(); - - /** - * Returns the system theme file directory for reference by other XNAT modules. - * @return the system theme file directory - */ - String getThemesPath(); - - /** - * Gets the currently selected global system theme from a cache for a specific user role, or secondarily from the theme.json file in the themes folder. - * @param role the name of the user role to fetch from the current global theme - * @return The currently selected system theme configuration - */ - ThemeConfig getTheme(String role); - - /** - * Gets the currently selected global system theme from a cache, or secondarily from the theme.json file in the themes folder. - * @return The currently selected global system theme configuration - */ - ThemeConfig getTheme(); - - /** - * Searches the theme directory if a global theme is applied and returns a path string to the referenced page to redirect to. - * If no global theme is selected or no overriding page is found the calling method should continue with it's default XNAT behavior. - * @return a path string the referenced page if found. Otherwise returns null. - */ - String getThemePage(String pageName); - - /** - * Searches the theme directory if a global theme is applied and returns a path string to the referenced theme and matching type to redirect to. - * If no global theme is selected or no overriding page with specified type is found the calling method should continue with it's default XNAT behavior. - * @return a path string the referenced theme and type if found. Otherwise returns null. - */ - String getThemePage(String pageName, String type); - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * @param themeConfig the theme configuration object to apply - */ - ThemeConfig setTheme(ThemeConfig themeConfig) throws ThemeNotFoundException; - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * @param name the theme name. Creates a theme configuration object with it applying defaults - */ - ThemeConfig setTheme(String name) throws ThemeNotFoundException; - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * Creates a theme configuration object with it applying a defaults path - * @param name the theme name. - * @param enabled flag specifying whether or not the theme should be active. - */ - ThemeConfig setTheme(String name, boolean enabled) throws ThemeNotFoundException; - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * @param name the theme name. - * @param path base theme directory path. - * @param enabled flag specifying whether or not the theme should be active. - */ - ThemeConfig setTheme(String name, String path, boolean enabled) throws ThemeNotFoundException; - - /** - * Loads the system theme options - * @return The list of the available theme packages (folder names) available under the system themes directory - */ - List<TypeOption> loadExistingThemes(); - - /** - * Checks if the specified theme exists. - * @param name the name of the theme to look for - * @return true if it could be found in the system theme directory - */ - boolean themeExists(String name); - - /** - * Extracts a zipped theme package from an given InputStream. - * @param inputStream from which to read the zipped data - * @return List of root level directories (theme names) that were extracted - * @throws IOException - */ - List<String> extractTheme(InputStream inputStream) throws IOException; - - /** - * Helper exception to report more specific errors - */ - class ThemeNotFoundException extends Exception{ - private String invalidTheme; - public ThemeNotFoundException(String invalidTheme) { - this.invalidTheme = invalidTheme; - } - public String getInvalidTheme() { - return invalidTheme; - } - } - - /** - * Helper class to organize the available themes for display in a select dropdown form - */ - class TypeOption implements Comparable<TypeOption> { - String value, label; - public TypeOption(String value, String label) { - this.value = value; - this.label = label; - } - public String getValue() { - return value; - } - public String getLabel() { - return label; - } - @Override - public int compareTo(@NotNull TypeOption that) { - return this.label.compareToIgnoreCase(that.label); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/nrg/xnat/services/impl/ThemeServiceImpl.java b/src/main/java/org/nrg/xnat/services/impl/ThemeServiceImpl.java deleted file mode 100644 index 7673f055a8de6ccf4ee006b0d123eee3376d638f..0000000000000000000000000000000000000000 --- a/src/main/java/org/nrg/xnat/services/impl/ThemeServiceImpl.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * org.nrg.xnat.turbine.modules.screens.ManageProtocol - * XNAT http://www.xnat.org - * Copyright (c) 2013, Washington University School of Medicine - * All Rights Reserved - * - * Released under the Simplified BSD. - * - * Author: Justin Cleveland <clevelandj@wustl.edu> (jcleve01) - * Last modified 2/30/2016 11:20 AM - */ -package org.nrg.xnat.services.impl; - -import com.fasterxml.jackson.core.JsonProcessingException; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; -import org.nrg.xnat.configuration.ThemeConfig; -import org.nrg.xnat.services.ThemeService; -import org.nrg.xnat.utils.SerializerService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.servlet.ServletContext; -import java.io.*; -import java.util.ArrayList; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -@Service -public class ThemeServiceImpl implements ThemeService { - private static String webRelativeThemePath="themes"; - private static String themesPath; - private static ThemeConfig themeConfig = null; - private static File themeFile = null; - private static final int FILE_BUFFER_SIZE = 4096; - - @Autowired - private SerializerService _serializer; - - @Autowired - private ServletContext servletContext; - - @PostConstruct - public void postServiceConstruction(){ - themesPath = servletContext.getRealPath(File.separator)+webRelativeThemePath; - themeFile = new File(themesPath + File.separator + "theme.json"); - File checkThemesPath = new File(themesPath); - if (!checkThemesPath.exists()) { - checkThemesPath.mkdir(); - } -System.out.println("Theme Path: "+themeFile); - servletContext.setAttribute("ThemeService", this); // This is probably a terrible way to attempt to do this. We would ideally add an instance of ThemeService to the XDAT class - } - - public String getThemesPath() { - return themesPath; - } - - /** - * Gets the currently selected system theme from an application servlet context cache, or secondarily from the - * theme.json file in the themes folder. - * @return The currently selected system theme configuration - */ - public ThemeConfig getTheme(String role) { - if(themeConfig != null){ - return themeConfig; - } else { // Read the last saved theme selection from the theme.json file in the themes - if (themeFile.exists()) { // directory in the event it can't be found in the application context. - try { // (ie. the server was just started/restarted) - BufferedReader reader = new BufferedReader(new FileReader(themeFile)); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - sb.append(line).append("\n"); - } - reader.close(); - String contents = sb.toString(); - themeConfig = _serializer.deserializeJson(contents, ThemeConfig.class); - } catch (IOException e) { - e.printStackTrace(); - } - } - try { - setTheme(themeConfig); - } catch (ThemeNotFoundException e) { - e.printStackTrace(); - } - } - if (role != null) { - // TODO: implement search through the roles array in the ThemeConfig object for a matching ThemeConfig object for the specified role - } - return themeConfig; - } - public ThemeConfig getTheme() { - return getTheme(null); - } - - /** - * Searches the theme directory if a global theme is applied and returns a path string to the referenced page to redirect to. - * If no global theme is selected or no overriding page is found the calling method should continue with it's default XNAT behavior. - * @return a path string the referenced page if found. Otherwise returns null. - */ - public String getThemePage(String pageName) { - return getThemePage(pageName, null); - } - - /** - * Searches the theme directory if a global theme is applied and returns a path string to the referenced theme and matching type to redirect to. - * If no global theme is selected or no overriding page with specified type is found the calling method should continue with it's default XNAT behavior. - * @return a path string the referenced theme and type if found. Otherwise returns null. - */ - public String getThemePage(String pageName, String type) { - String pagePath; - ThemeConfig theme = getTheme(); - if(theme == null){ - return null; - } else if (pageName == null){ - return null; - } else { // Read the last saved theme selection from the theme.json file in the themes - pagePath = checkThemeFileExists(theme, pageName, type); - } - return pagePath; - } - - /** - * Checks for the existence of a file name with a given set of accepted file extensions in the theme directory - * and returns a relative web path string the referenced page if found. - * @return a relative web path string prioritized by extension to the referenced page if found. Otherwise returns null. - */ - private String checkThemeFileExists(ThemeConfig theme, String pageName) { - return checkThemeFileExists(theme, pageName, null); - } - - private String checkThemeFileExists(ThemeConfig theme, String pageName, String type) { - String pagePath = null, typeSep = type + "s" + File.separator; - String[] extensions = new String[]{}; - String[] pageExts = new String[]{"jsp", "vm", "htm", "html"}; - String[] scriptExts = new String[]{"js"}; - String[] styleExts = new String[]{"css"}; - if("page".equals(type)){ - extensions = (String[]) ArrayUtils.addAll(extensions, pageExts); - } - if("script".equals(type)){ - extensions = (String[]) ArrayUtils.addAll(extensions, scriptExts); - } - if("style".equals(type)){ - extensions = (String[]) ArrayUtils.addAll(extensions, styleExts); - } - if(type == null){ - typeSep = ""; - extensions = (String[]) ArrayUtils.addAll(extensions, pageExts); - extensions = (String[]) ArrayUtils.addAll(extensions, scriptExts); - extensions = (String[]) ArrayUtils.addAll(extensions, styleExts); - } - for (String ext : extensions) { - File themePageFile = new File(theme.getPath() + File.separator + typeSep + pageName + "." + ext); - if(themePageFile.exists()) { - if(type != null){ - typeSep = type + "s/"; // This is awful and should be set once up above - } - pagePath = "/" + webRelativeThemePath + "/" + theme.getName() + "/" + typeSep + pageName + "." + ext; - break; - } - } - return pagePath; - } - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * @param themeConfig the theme configuration object to apply - */ - public ThemeConfig setTheme(ThemeConfig themeConfig) throws ThemeNotFoundException { - try { - if (themeConfig == null){ - themeConfig = new ThemeConfig(); - } - if(themeExists(themeConfig.getName())) { - String themeJson = _serializer.toJson(themeConfig); - if (!themeFile.exists()) { - themeFile.createNewFile(); - } - FileWriter writer = new FileWriter(themeFile); - writer.write(themeJson); - writer.flush(); - writer.close(); - ThemeServiceImpl.themeConfig = themeConfig; - } else { - throw new ThemeNotFoundException(themeConfig.getName()); - } - } catch (JsonProcessingException e) { - e.printStackTrace(); - // TODO: rethrow this and respond as an internal server error - } catch (IOException e) { - e.printStackTrace(); - // TODO: rethrow this and respond as an internal server error - } - return themeConfig; - } - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * @param name the theme name. Creates a theme configuration object with it applying defaults - */ - public ThemeConfig setTheme(String name) throws ThemeNotFoundException { - return setTheme(name, true); - } - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * Creates a theme configuration object with it applying a defaults path - * @param name the theme name. - * @param enabled flag specifying whether or not the theme should be active. - */ - public ThemeConfig setTheme(String name, boolean enabled) throws ThemeNotFoundException { - return setTheme(new ThemeConfig(name, themesPath + File.separator + name, enabled)); - } - - /** - * Sets the currently selected system theme in the theme.json file in the web application's themes folder and caches it. - * @param name the theme name. - * @param path base theme directory path. - * @param enabled flag specifying whether or not the theme should be active. - */ - public ThemeConfig setTheme(String name, String path, boolean enabled) throws ThemeNotFoundException { - return setTheme(new ThemeConfig(name, path, enabled)); - } - - /** - * Loads the system theme options - * @return The list of the available theme packages (folder names) available under the system themes directory - */ - public List<TypeOption> loadExistingThemes() { - ArrayList<TypeOption> themeOptions = new ArrayList<>(); - themeOptions.add(new TypeOption(null, "None")); - File f = new File(themesPath); // current directory - FileFilter directoryFilter = new FileFilter() { - public boolean accept(File file) { - return file.isDirectory(); - } - }; - File[] files = f.listFiles(directoryFilter); - if(files != null) { - for (File file : files) { - if (file.isDirectory()) { - themeOptions.add(new TypeOption(file.getName(), file.getName())); - } - } - } - return themeOptions; - } - - /** - * Checks if the specified theme exists. - * @param name the name of the theme to look for - * @return true if it could be found in the system theme directory - */ - public boolean themeExists(String name) { - if(name == null) { - return true; - } else if(StringUtils.isEmpty(name)){ - return false; - } else { - List<TypeOption> themeList = loadExistingThemes(); - for (TypeOption to: themeList) { - if(name.equals(to.getValue())){ - return true; - } - } - } - return false; - } - - /** - * Extracts a zipped theme package from an given InputStream. - * @param inputStream from which to read the zipped data - * @return List of root level directories (theme names) that were extracted - * @throws IOException - */ - public List<String> extractTheme(InputStream inputStream) throws IOException { - final List<String> rootDirs = new ArrayList<>(); - ZipInputStream zipIn = new ZipInputStream(inputStream); - ZipEntry entry = zipIn.getNextEntry(); - while (entry != null) { // iterate over entries in the zip file - String filePath = this.getThemesPath() + File.separator + entry.getName(); - if (!entry.isDirectory()) { // if the entry is a file, extract it // TODO: Make sure we get a directory the first iteration through (fail otherwise) so that no files get dumped in the root themes directory - this.extractFile(zipIn, filePath); - } else { // if the entry is a directory, make the directory - String rootDir = entry.getName(); - int slashIndex = rootDir.indexOf('/'); - if(slashIndex>1){ - int nextSlashIndex = rootDir.indexOf('/', slashIndex+1); - if(nextSlashIndex<0) { - rootDir = rootDir.substring(0, slashIndex); - rootDirs.add(rootDir); - } - } - File dir = new File(filePath); - dir.mkdir(); - } - zipIn.closeEntry(); - entry = zipIn.getNextEntry(); - } - zipIn.close(); - inputStream.close(); - return rootDirs; - } - - /** - * Extracts a single zip entry (file entry) - * @param zip zip input stream to extract it from - * @param path to the file within the zip package - * @throws IOException - */ - private void extractFile(ZipInputStream zip, String path) throws IOException { - BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(path)); - byte[] bytes = new byte[FILE_BUFFER_SIZE]; - int length; - while ((length = zip.read(bytes)) != -1) { - os.write(bytes, 0, length); - } - os.close(); - } -} \ No newline at end of file diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/Index.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/Index.java index 64953b9ed8e8195772189a7d17afba7b9dd3c21a..4fcc18635ad2bef853db38c058d44ad09f72f96c 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/Index.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/Index.java @@ -14,7 +14,6 @@ import java.util.Date; import org.apache.turbine.util.RunData; import org.apache.velocity.context.Context; -import org.nrg.xdat.XDAT; import org.nrg.xdat.security.helpers.UserHelper; import org.nrg.xdat.turbine.modules.screens.SecureScreen; import org.nrg.xdat.turbine.utils.TurbineUtils; @@ -22,32 +21,18 @@ import org.nrg.xft.db.PoolDBUtils; import org.nrg.xft.security.UserI; import org.nrg.xnat.helpers.prearchive.PrearcDatabase; -import org.nrg.xnat.services.ThemeService; + import org.nrg.xnat.turbine.utils.ProjectAccessRequest; public class Index extends SecureScreen { @Override protected void doBuildTemplate(RunData data, Context context) throws Exception { - ThemeService themeService = XDAT.getContextService().getBean(ThemeService.class); -// String themedLandingPath = themeService.getThemePage("Landing"); -// if(themedLandingPath != null) { -// doRedirect(data, themedLandingPath); -// data.setRedirectURI(themedLandingPath); -// } - String themedRedirect = themeService.getThemePage("Landing"); // put all this in a method in the theme service with an optional requested page parameter + String themedRedirect = themeService.getThemePage("Landing"); // TODO: put all this in a method in the theme service with an optional requested page parameter if(themedRedirect != null) { context.put("themedRedirect", themedRedirect); return; } - String themedStyle = themeService.getThemePage("theme", "style"); - if(themedStyle != null) { - context.put("themedStyle", themedStyle); - } - String themedScript = themeService.getThemePage("theme", "script"); - if(themedScript != null) { - context.put("themedScript", themedScript); - } UserI user = TurbineUtils.getUser(data); diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/Login.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/Login.java index 8b2785b2df6b22e7853a4bc3ad43b6a5adb02cc3..60e02df12b06c62f6d75659643a2aa570a8e9c42 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/Login.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/Login.java @@ -1,5 +1,4 @@ /* - * org.nrg.xnat.turbine.modules.screens.ManageProtocol * XNAT http://www.xnat.org * Copyright (c) 2013, Washington University School of Medicine * All Rights Reserved @@ -15,30 +14,25 @@ import org.apache.log4j.Logger; import org.apache.turbine.util.RunData; import org.apache.velocity.context.Context; import org.nrg.xdat.XDAT; -import org.nrg.xnat.services.ThemeService; +import org.nrg.xdat.services.ThemeService; public class Login extends org.nrg.xdat.turbine.modules.screens.Login { public final static Logger logger = Logger.getLogger(XDATScreen_themes.class); @Override - protected void doBuildTemplate(RunData data, Context context) throws Exception { + protected void doBuildTemplate(RunData data, Context c) throws Exception { ThemeService themeService = XDAT.getContextService().getBean(ThemeService.class); -// String themedLoginPath = themeService.getThemePage("Login"); -// if(themedLoginPath != null) { -// doRedirect(data, themedLoginPath); -// data.setRedirectURI(themedLoginPath); -// } String themedRedirect = themeService.getThemePage("Login"); if(themedRedirect != null) { - context.put("themedRedirect", themedRedirect); + c.put("themedRedirect", themedRedirect); return; } String themedStyle = themeService.getThemePage("theme", "style"); if(themedStyle != null) { - context.put("themedStyle", themedStyle); + c.put("themedStyle", themedStyle); } String themedScript = themeService.getThemePage("theme", "script"); if(themedScript != null) { - context.put("themedScript", themedScript); + c.put("themedScript", themedScript); } } } \ No newline at end of file diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/UploadAppletScreen.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/UploadAppletScreen.java index 46ad360a7cc91d8c106c383877badbb8ad1f263b..743912a9ac7d87995869917082b8510a853597ef 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/UploadAppletScreen.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/UploadAppletScreen.java @@ -8,7 +8,7 @@ import org.nrg.xdat.security.helpers.Permissions; import org.nrg.xdat.turbine.modules.screens.SecureScreen; import org.nrg.xft.security.UserI; import org.nrg.xnat.utils.AppletConfig; -import org.nrg.xnat.utils.SerializerService; +import org.nrg.framework.services.SerializerService; /** * Contains basic methods used by upload applet screen classes. diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_admin_options.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_admin_options.java index 3bb1cb82c45c4456bcd12ebc23c1272afaa89fa2..83a7291d7c1b502a557bdfdcded13b359997c391 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_admin_options.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_admin_options.java @@ -1,5 +1,4 @@ /* - * org.nrg.xnat.turbine.modules.screens.ManageProtocol * XNAT http://www.xnat.org * Copyright (c) 2013, Washington University School of Medicine * All Rights Reserved @@ -15,26 +14,11 @@ package org.nrg.xnat.turbine.modules.screens; import org.apache.log4j.Logger; import org.apache.turbine.util.RunData; import org.apache.velocity.context.Context; -import org.nrg.xdat.XDAT; import org.nrg.xdat.turbine.modules.screens.SecureScreen; -import org.nrg.xnat.services.ThemeService; - -/** - * Created by jcleve01 on 1/22/2016. - */ public class XDATScreen_admin_options extends SecureScreen { public final static Logger logger = Logger.getLogger(XDATScreen_admin_options.class); @Override protected void doBuildTemplate(RunData data, Context context) throws Exception { - ThemeService themeService = XDAT.getContextService().getBean(ThemeService.class); - String themedStyle = themeService.getThemePage("theme", "style"); - if (themedStyle != null) { - context.put("themedStyle", themedStyle); - } - String themedScript = themeService.getThemePage("theme", "script"); - if (themedScript != null) { - context.put("themedScript", themedScript); - } } } diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_themes.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_themes.java index 85a637e82cefc55d0ad151c935d10300c1a0e5fc..1308f443baa5d056be40e61f5c5ddbe725541e8e 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_themes.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/XDATScreen_themes.java @@ -1,5 +1,4 @@ /* - * org.nrg.xnat.turbine.modules.screens.ManageProtocol * XNAT http://www.xnat.org * Copyright (c) 2013, Washington University School of Medicine * All Rights Reserved @@ -15,26 +14,11 @@ package org.nrg.xnat.turbine.modules.screens; import org.apache.log4j.Logger; import org.apache.turbine.util.RunData; import org.apache.velocity.context.Context; -import org.nrg.xdat.XDAT; import org.nrg.xdat.turbine.modules.screens.SecureScreen; -import org.nrg.xnat.services.ThemeService; - -/** - * Created by jcleve01 on 1/22/2016. - */ public class XDATScreen_themes extends SecureScreen { public final static Logger logger = Logger.getLogger(XDATScreen_themes.class); @Override protected void doBuildTemplate(RunData data, Context context) throws Exception { - ThemeService themeService = XDAT.getContextService().getBean(ThemeService.class); - String themedStyle = themeService.getThemePage("theme", "style"); - if (themedStyle != null) { - context.put("themedStyle", themedStyle); - } - String themedScript = themeService.getThemePage("theme", "script"); - if (themedScript != null) { - context.put("themedScript", themedScript); - } } } diff --git a/src/main/java/org/nrg/xnat/utils/SerializerService.java b/src/main/java/org/nrg/xnat/utils/SerializerService.java deleted file mode 100644 index 529f10b6777439e32150894975a3fb9f594621f2..0000000000000000000000000000000000000000 --- a/src/main/java/org/nrg/xnat/utils/SerializerService.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.nrg.xnat.utils; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import javax.inject.Named; -import java.io.IOException; - -@Service -public class SerializerService { - public JsonNode deserializeJson(final String json) throws IOException { - return _jsonObjectMapper.readTree(json); - } - - public <T> T deserializeJson(final String json, final Class<T> clazz) throws IOException { - return _jsonObjectMapper.readValue(json, clazz); - } - - public <T> T deserializeJson(final String json, final TypeReference<T> typeRef) throws IOException { - return _jsonObjectMapper.readValue(json, typeRef); - } - - public <T> String toJson(final T instance) throws IOException { - return _jsonObjectMapper.writeValueAsString(instance); - } - - public JsonNode deserializeYaml(final String yaml) throws IOException { - return _yamlObjectMapper.readTree(yaml); - } - - public <T> T deserializeYaml(final String yaml, Class<T> clazz) throws IOException { - return _yamlObjectMapper.readValue(yaml, clazz); - } - - public <T> T deserializeYaml(final String yaml, final TypeReference<T> typeRef) throws IOException { - return _yamlObjectMapper.readValue(yaml, typeRef); - } - - public <T> String toYaml(final T instance) throws IOException { - return _yamlObjectMapper.writeValueAsString(instance); - } - - @Inject - @Named("jsonObjectMapper") - private ObjectMapper _jsonObjectMapper; - - @Inject - @Named("yamlObjectMapper") - private ObjectMapper _yamlObjectMapper; -} diff --git a/src/main/webapp/xnat-templates/navigations/HeaderIncludes.vm b/src/main/webapp/xnat-templates/navigations/HeaderIncludes.vm index d7046f0bf41af35a976d23d49adee590f8cd93d8..b370bdf5ba00ecd776143e5b91fdaf8646af31be 100755 --- a/src/main/webapp/xnat-templates/navigations/HeaderIncludes.vm +++ b/src/main/webapp/xnat-templates/navigations/HeaderIncludes.vm @@ -22,6 +22,12 @@ </script> #end +#if ($theme) +<script type="text/javascript"> + XNAT.theme = $theme}"; +</script> +#end + <!-- load polyfills before ANY other JavaScript --> <script type="text/javascript" src="$content.getURI('scripts/polyfills.js')"></script>