From c6572a11cb15652cc09f08c24298433e5f6d3a80 Mon Sep 17 00:00:00 2001 From: lum Date: Fri, 22 Nov 2024 16:25:25 -0800 Subject: [PATCH 1/3] checkpoint : remove GWT study designer --- .gitattributes | 9 - api/schemas/studyDesign.xsd | 187 --- study/src/org/labkey/study/StudyModule.java | 44 +- .../designer/DesignerController.java | 1167 ----------------- .../labkey/study/designer/JSONSerializer.java | 377 ------ .../labkey/study/designer/SaveException.java | 29 - .../designer/StudyDefinitionServiceImpl.java | 322 ----- .../study/designer/StudyDesignInfo.java | 157 --- .../study/designer/StudyDesignManager.java | 599 --------- .../study/designer/StudyDesignVersion.java | 149 --- .../labkey/study/designer/XMLSerializer.java | 425 ------ .../designer/view/StudyDesignsWebPart.java | 142 -- .../designer/view/createRepositoryWizard.jsp | 277 ---- ...tudyDesignSummary.jsp => studySummary.jsp} | 107 +- .../src/org/labkey/study/model/StudyImpl.java | 5 +- .../org/labkey/study/model/StudyManager.java | 1 - .../study/view/VaccineStudyWebPart.java | 110 -- .../org/labkey/study/view/vaccineStudy.jsp | 79 -- 18 files changed, 24 insertions(+), 4162 deletions(-) delete mode 100644 api/schemas/studyDesign.xsd delete mode 100644 study/src/org/labkey/study/controllers/designer/DesignerController.java delete mode 100644 study/src/org/labkey/study/designer/JSONSerializer.java delete mode 100644 study/src/org/labkey/study/designer/SaveException.java delete mode 100644 study/src/org/labkey/study/designer/StudyDefinitionServiceImpl.java delete mode 100644 study/src/org/labkey/study/designer/StudyDesignInfo.java delete mode 100644 study/src/org/labkey/study/designer/StudyDesignVersion.java delete mode 100644 study/src/org/labkey/study/designer/XMLSerializer.java delete mode 100644 study/src/org/labkey/study/designer/view/StudyDesignsWebPart.java delete mode 100644 study/src/org/labkey/study/designer/view/createRepositoryWizard.jsp rename study/src/org/labkey/study/designer/view/{studyDesignSummary.jsp => studySummary.jsp} (50%) delete mode 100644 study/src/org/labkey/study/view/VaccineStudyWebPart.java delete mode 100644 study/src/org/labkey/study/view/vaccineStudy.jsp diff --git a/.gitattributes b/.gitattributes index 93bd123708d..7953a0c8301 100644 --- a/.gitattributes +++ b/.gitattributes @@ -130,7 +130,6 @@ api/schemas/rdfTypes.xsd -text api/schemas/report.xsd -text api/schemas/reportProps.xsd -text api/schemas/study.xsd -text -api/schemas/studyDesign.xsd -text api/schemas/studyViews.xsd -text api/schemas/view.xsd -text api/schemas/viewCategory.xsd -text @@ -2702,7 +2701,6 @@ study/src/org/labkey/study/BaseCohortFilter.java -text study/src/org/labkey/study/CohortFilterFactory.java -text study/src/org/labkey/study/controllers/BaseStudyController.java -text study/src/org/labkey/study/controllers/CreateChildStudyAction.java -text -study/src/org/labkey/study/controllers/designer/DesignerController.java -text study/src/org/labkey/study/controllers/ParticipantGroupController.java -text study/src/org/labkey/study/controllers/reports/ReportsController.java -text study/src/org/labkey/study/controllers/reports/StudyManageReportsBean.java -text @@ -2715,15 +2713,8 @@ study/src/org/labkey/study/dataset/DatasetSnapshotProvider.java -text study/src/org/labkey/study/dataset/DatasetViewProvider.java -text study/src/org/labkey/study/dataset/SnapshotDependency.java -text study/src/org/labkey/study/DefragmentParticipantVisitIndexesTask.java -text -study/src/org/labkey/study/designer/JSONSerializer.java -text -study/src/org/labkey/study/designer/StudyDefinitionServiceImpl.java -text -study/src/org/labkey/study/designer/StudyDesignInfo.java -text study/src/org/labkey/study/designer/StudyDesignManager.java -text -study/src/org/labkey/study/designer/StudyDesignVersion.java -text study/src/org/labkey/study/designer/StudySchedule.java -text -study/src/org/labkey/study/designer/view/CreateRepositoryWizard.jsp -text -study/src/org/labkey/study/designer/view/StudyDesignsWebPart.java -text -study/src/org/labkey/study/designer/XMLSerializer.java -text study/src/org/labkey/study/importer/AssayScheduleImporter.java -text study/src/org/labkey/study/importer/CohortImporter.java -text study/src/org/labkey/study/importer/CreateChildStudyPipelineJob.java -text diff --git a/api/schemas/studyDesign.xsd b/api/schemas/studyDesign.xsd deleted file mode 100644 index 10e9488ebff..00000000000 --- a/api/schemas/studyDesign.xsd +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/study/src/org/labkey/study/StudyModule.java b/study/src/org/labkey/study/StudyModule.java index ba53fff66f0..a4073e3c3e6 100644 --- a/study/src/org/labkey/study/StudyModule.java +++ b/study/src/org/labkey/study/StudyModule.java @@ -68,7 +68,6 @@ import org.labkey.api.services.ServiceRegistry; import org.labkey.api.settings.AdminConsole; import org.labkey.api.settings.AdminConsole.OptionalFeatureFlag; -import org.labkey.api.settings.OptionalFeatureService; import org.labkey.api.settings.OptionalFeatureService.FeatureType; import org.labkey.api.specimen.SpecimenSampleTypeDomainKind; import org.labkey.api.specimen.model.AdditiveTypeDomainKind; @@ -126,7 +125,6 @@ import org.labkey.study.controllers.StudyDefinitionController; import org.labkey.study.controllers.StudyDesignController; import org.labkey.study.controllers.StudyPropertiesController; -import org.labkey.study.controllers.designer.DesignerController; import org.labkey.study.controllers.publish.PublishController; import org.labkey.study.controllers.reports.ReportsController; import org.labkey.study.controllers.security.SecurityController; @@ -134,7 +132,6 @@ import org.labkey.study.dataset.DatasetNotificationInfoProvider; import org.labkey.study.dataset.DatasetSnapshotProvider; import org.labkey.study.dataset.DatasetViewProvider; -import org.labkey.study.designer.view.StudyDesignsWebPart; import org.labkey.study.importer.StudyImporterFactory; import org.labkey.study.model.CohortDomainKind; import org.labkey.study.model.ContinuousDatasetDomainKind; @@ -176,7 +173,6 @@ import org.labkey.study.reports.StudyReportUIProvider; import org.labkey.study.view.DatasetsWebPartView; import org.labkey.study.view.StudyListWebPartFactory; -import org.labkey.study.view.StudySummaryWebPartFactory; import org.labkey.study.view.StudyToolsWebPartFactory; import org.labkey.study.view.SubjectDetailsWebPartFactory; import org.labkey.study.view.SubjectsWebPart; @@ -210,9 +206,8 @@ public class StudyModule extends SpringModule implements SearchService.DocumentP public static final WebPartFactory dataToolsWebPartFactory = new StudyToolsWebPartFactory(); public static final WebPartFactory datasetsPartFactory = new DatasetsWebPartFactory(); public static final WebPartFactory immunizationScheduleWebpartFactory = new ImmunizationScheduleWebpartFactory(); - public static final WebPartFactory manageStudyPartFactory = new StudySummaryWebPartFactory(); - public static final WebPartFactory studyDesignSummaryWebPartFactory = new StudyDesignSummaryWebPartFactory(); - public static final WebPartFactory studyDesignsWebPartFactory = new StudyDesignsWebPartFactory(); + public static final WebPartFactory manageStudyPartFactory = new org.labkey.study.view.StudySummaryWebPartFactory(); + public static final WebPartFactory studyDesignSummaryWebPartFactory = new StudySummaryWebPartFactory(); public static final WebPartFactory studyListWebPartFactory = new StudyListWebPartFactory(); public static final WebPartFactory studyScheduleWebPartFactory = new StudyScheduleWebPartFactory(); public static final WebPartFactory subjectDetailsWebPartFactory = new SubjectDetailsWebPartFactory(); @@ -241,7 +236,6 @@ protected void init() addController("publish", PublishController.class); addController("study-definition", StudyDefinitionController.class); addController("study-design", StudyDesignController.class); - addController("study-designer", DesignerController.class); addController("study-properties", StudyPropertiesController.class); addController("study-reports", ReportsController.class); addController("study-security", SecurityController.class); @@ -311,7 +305,6 @@ protected Collection createWebPartFactories() manageStudyPartFactory, reportsPartFactory, studyDesignSummaryWebPartFactory, - studyDesignsWebPartFactory, studyListWebPartFactory, studyScheduleWebPartFactory, subjectDetailsWebPartFactory, @@ -687,36 +680,9 @@ public WebPartView getWebPartView(@NotNull ViewContext portalCtx, @NotNull Porta } } - private static class StudyDesignsWebPartFactory extends BaseWebPartFactory + private static class StudySummaryWebPartFactory extends BaseWebPartFactory { - public StudyDesignsWebPartFactory() - { - super("Vaccine Study Protocols"); - addLegacyNames("Study Designs"); - } - - @Override - public WebPartView getWebPartView(@NotNull ViewContext portalCtx, @NotNull Portal.WebPart webPart) - { - if (OptionalFeatureService.get().isFeatureEnabled(Study.GWT_STUDY_DESIGN)) - return new StudyDesignsWebPart(portalCtx, true); - else - return null; - } - - @Override - public boolean isAvailable(Container c, String scope, String location) - { - if (OptionalFeatureService.get().isFeatureEnabled(Study.GWT_STUDY_DESIGN)) - return super.isAvailable(c, scope, location); - else - return false; - } - } - - private static class StudyDesignSummaryWebPartFactory extends BaseWebPartFactory - { - public StudyDesignSummaryWebPartFactory() + public StudySummaryWebPartFactory() { super("Study Protocol Summary"); } @@ -724,7 +690,7 @@ public StudyDesignSummaryWebPartFactory() @Override public WebPartView getWebPartView(@NotNull ViewContext portalCtx, @NotNull Portal.WebPart webPart) { - JspView view = new JspView("/org/labkey/study/designer/view/studyDesignSummary.jsp"); + JspView view = new JspView("/org/labkey/study/designer/view/studySummary.jsp"); view.setTitle("Study Protocol Summary"); view.setFrame(WebPartView.FrameType.PORTAL); return view; diff --git a/study/src/org/labkey/study/controllers/designer/DesignerController.java b/study/src/org/labkey/study/controllers/designer/DesignerController.java deleted file mode 100644 index 66e94635bb0..00000000000 --- a/study/src/org/labkey/study/controllers/designer/DesignerController.java +++ /dev/null @@ -1,1167 +0,0 @@ -/* - * Copyright (c) 2008-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.study.controllers.designer; - -import gwt.client.org.labkey.study.designer.client.model.GWTCohort; -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpSession; -import org.apache.commons.lang3.StringUtils; -import org.json.JSONArray; -import org.json.JSONObject; -import org.labkey.api.action.ApiJsonWriter; -import org.labkey.api.action.ApiResponse; -import org.labkey.api.action.ApiSimpleResponse; -import org.labkey.api.action.ExportAction; -import org.labkey.api.action.FormHandlerAction; -import org.labkey.api.action.FormViewAction; -import org.labkey.api.action.GWTServiceAction; -import org.labkey.api.action.ReadOnlyApiAction; -import org.labkey.api.action.SimpleRedirectAction; -import org.labkey.api.action.SimpleViewAction; -import org.labkey.api.action.SpringActionController; -import org.labkey.api.announcements.DiscussionService; -import org.labkey.api.collections.CaseInsensitiveHashMap; -import org.labkey.api.data.Container; -import org.labkey.api.data.ContainerManager; -import org.labkey.api.data.DataRegionSelection; -import org.labkey.api.gwt.server.BaseRemoteService; -import org.labkey.api.portal.ProjectUrls; -import org.labkey.api.reader.ColumnDescriptor; -import org.labkey.api.reader.TabLoader; -import org.labkey.api.security.RequiresPermission; -import org.labkey.api.security.User; -import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.security.permissions.DeletePermission; -import org.labkey.api.security.permissions.ReadPermission; -import org.labkey.api.security.permissions.UpdatePermission; -import org.labkey.api.settings.OptionalFeatureService; -import org.labkey.api.specimen.SpecimenMigrationService; -import org.labkey.api.study.MapArrayExcelWriter; -import org.labkey.api.study.Study; -import org.labkey.api.study.StudyService; -import org.labkey.api.study.TimepointType; -import org.labkey.api.util.PageFlowUtil; -import org.labkey.api.util.URLHelper; -import org.labkey.api.view.ActionURL; -import org.labkey.api.view.HtmlView; -import org.labkey.api.view.HttpView; -import org.labkey.api.view.JspView; -import org.labkey.api.view.NavTree; -import org.labkey.api.view.NotFoundException; -import org.labkey.api.view.RedirectException; -import org.labkey.api.view.VBox; -import org.labkey.api.view.template.ClientDependency; -import org.labkey.study.controllers.BaseStudyController; -import org.labkey.study.designer.JSONSerializer; -import org.labkey.study.designer.StudyDefinitionServiceImpl; -import org.labkey.study.designer.StudyDesignInfo; -import org.labkey.study.designer.StudyDesignManager; -import org.labkey.study.designer.StudyDesignVersion; -import org.labkey.study.designer.XMLSerializer; -import org.labkey.study.designer.view.StudyDesignsWebPart; -import org.labkey.study.view.StudyGWTView; -import org.labkey.study.view.VaccineStudyWebPart; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.web.servlet.ModelAndView; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.labkey.api.study.publish.StudyPublishService.SOURCE_LSID_PROPERTY_NAME; - -public class DesignerController extends SpringActionController -{ - public enum WizardStep - { - INIT(0, null), - PICK_FOLDER(1, "Choose Destination Folder"), - SHOW_PARTICIPANTS(2, "Subject Information"), - UPLOAD_PARTICIPANTS(3, "Upload Subject Information"), - SHOW_SAMPLES(4, "Sample Information"), - UPLOAD_SAMPLES(5, "Upload Sample Information"), - CONFIRM(6, "Confirm"); - - WizardStep(int number, String title) - { - _number = number; - _title = title; - } - - public String getTitle() - { - return _title; - } - - public int getNumber() - { - return _number; - } - - private final String _title; - private final int _number; - - public static WizardStep fromNumber(int number) - { - for (WizardStep step : values()) - if (step._number == number) - return step; - - return null; - } - } - - private static final String TEMPLATE_NAME = "Template"; - private static final ColumnDescriptor[] PARTICIPANT_COLS = new ColumnDescriptor[]{ - new ColumnDescriptor("ParticipantId", String.class), - new ColumnDescriptor("Cohort", String.class), - new ColumnDescriptor("StartDate", Date.class) - }; - - private static final String PARTICIPANT_KEY = DesignerController.class + ".participants"; - private static final String SPECIMEN_KEY = DesignerController.class + ".specimens"; - - private static final DefaultActionResolver ACTION_RESOLVER = new DefaultActionResolver(DesignerController.class); - - public DesignerController() - { - setActionResolver(ACTION_RESOLVER); - } - - @RequiresPermission(ReadPermission.class) - public static class BeginAction extends SimpleViewAction - { - - @Override - public ModelAndView getView(Object o, BindException errors) - { - return new StudyDesignsWebPart(getViewContext(), false); - } - - @Override - public void addNavTrail(NavTree root) - { - root.addChild("Study Protocol Registration"); - } - } - - @RequiresPermission(DeletePermission.class) - public static class DeleteAction extends FormHandlerAction - { - - @Override - public void validateCommand(Object target, Errors errors) {} - - @Override - public boolean handlePost(Object o, BindException errors) - { - Set selectedRows = DataRegionSelection.getSelected(getViewContext(), true); - for (String row : selectedRows) - { - StudyDesignManager.get().deleteStudyDesign(getContainer(), Integer.parseInt(row)); - } - return true; - } - - @Override - public ActionURL getSuccessURL(Object o) - { - return new ActionURL(BeginAction.class, getContainer()); - } - } - - @RequiresPermission(AdminPermission.class) - public class CancelWizardAction extends SimpleRedirectAction - { - @Override - public ActionURL getRedirectURL(CreateRepositoryForm form) - { - setParticipants(null); - setSpecimens(null); - ActionURL designURL = new ActionURL(DesignerAction.class, getContainer()); - designURL.addParameter("studyId", form.getStudyId()); - return designURL; - } - } - - @RequiresPermission(ReadPermission.class) - public static class DesignerAction extends SimpleViewAction - { - @Override - public void addNavTrail(NavTree root) - { - root.addChild("Study Protocol Registration"); - } - - @Override - public ModelAndView getView(StudyDesignForm form, BindException errors) throws Exception - { - if (null == form.getPanel()) //Old code to handle deprecated case of designs not affiliated with studies - { - Map params = new HashMap<>(); - params.put("studyId", Integer.toString(form.getStudyId())); - StudyDesignInfo info = StudyDesignManager.get().getStudyDesign(getContainer(), form.getStudyId()); - //If url is to source container and we've moved to study folder throw the new container - if (null != info && !info.getContainer().equals(getContainer())) - { - ActionURL url = new ActionURL(DesignerAction.class, info.getContainer()); - url.addParameter("studyId", form.getStudyId()); - throw new RedirectException(url); - } - - int revision = form.getRevision(); - if (revision == 0 && form.getStudyId() > 0) - { - Integer revInteger = StudyDesignManager.get().getLatestRevisionNumber(getContainer(), form.getStudyId()); - if (revInteger == null) - { - throw new NotFoundException("No revision found for Study ID: " + form.getStudyId()); - } - revision = revInteger.intValue(); - } - params.put("revision", Integer.toString(revision)); - params.put("edit", getViewContext().hasPermission(UpdatePermission.class) && form.isEdit() ? "true" : "false"); - boolean canEdit = OptionalFeatureService.get().isFeatureEnabled(Study.GWT_STUDY_DESIGN) && getViewContext().hasPermission(UpdatePermission.class); - params.put("canEdit", Boolean.toString(canEdit)); - boolean canAdmin = getViewContext().hasPermission(AdminPermission.class); - params.put("canAdmin", Boolean.toString(canAdmin)); - params.put("showAllLookups", "true"); - params.put("canCreateRepository", Boolean.toString(canEdit && null != info && !info.isActive())); - if (null != StringUtils.trimToNull(form.getFinishURL())) - params.put("finishURL", form.getFinishURL()); - - HttpView studyView = new StudyGWTView(gwt.client.org.labkey.study.designer.client.Designer.class, params); - if (0 != form.getStudyId() && info != null && DiscussionService.get() != null) - { - HttpView discussion = DiscussionService.get().getDiscussionArea( - getViewContext(), - info.getLsid().toString(), - getViewContext().getActionURL(), - "Discussion of " + info.getLabel() + " revision " + revision, - true, false); - if (discussion != null) - { - VBox vbox = new VBox(); - vbox.addClientDependency(ClientDependency.fromPath("study/StudyVaccineDesign.css")); - if (null != getViewContext().getRequest().getParameter("discussion.start") || null != getViewContext().getRequest().getParameter("discussion.id")) - vbox.addView(HtmlView.of("Study information is on this page below the discussion.")); - vbox.addView(discussion); - vbox.addView(studyView); - studyView = vbox; - } - } - return studyView; - } - else - { - VaccineStudyWebPart.Model model = new VaccineStudyWebPart.Model(); - Study study = BaseStudyController.getStudyRedirectIfNull(getContainer()); - StudyDesignInfo info = StudyDesignManager.get().ensureDesignForStudy(getUser(), study, getContainer().hasPermission(getUser(), AdminPermission.class)); - if (null == info) - return HtmlView.of("Study design information not available for this study. Contact an administrator to configure the study design."); - - model.setStudyId(info.getStudyId()); - model.setEditMode(form.isEdit()); - model.setPanel(form.getPanel()); - model.setFinishURL(form.getFinishURL()); - - return new VaccineStudyWebPart(model); - } - } - } - - @RequiresPermission(ReadPermission.class) - public static class DefinitionServiceAction extends GWTServiceAction - { - @Override - protected BaseRemoteService createService() - { - return new StudyDefinitionServiceImpl(getViewContext()); - } - } - - @RequiresPermission(ReadPermission.class) - public static class EditTemplateAction extends SimpleRedirectAction - { - @Override - public ActionURL getRedirectURL(StudyDesignForm studyDesignForm) throws Exception - { - StudyDesignInfo info = getTemplateInfo(getUser(), getContainer()); - ActionURL url = new ActionURL(DesignerAction.class, info.getContainer()); - url.addParameter("edit", "true"); - url.addParameter("studyId", info.getStudyId()); - url.addParameter("finishURL", new ActionURL(BeginAction.class, info.getContainer()).toString()); - return url; - } - } - - @SuppressWarnings("unchecked") - @RequiresPermission(AdminPermission.class) - public class GetParticipantExcelAction extends ExportAction - { - @Override - public void export(CreateRepositoryForm form, HttpServletResponse response, BindException errors) - { - List> participantGroup = new ArrayList<>(); - int participantNum = 1; - for (GWTCohort cohort : getStudyDefinition(form).getGroups()) - { - for (int i = 0; i < cohort.getCount(); i++) - { - HashMap hm = new HashMap<>(); - hm.put("SubjectId", participantNum++); - hm.put("Cohort", cohort.getName()); - hm.put("StartDate", form.getBeginDate()); - participantGroup.add(hm); - } - } - - ColumnDescriptor[] xlCols = new ColumnDescriptor[3]; - xlCols[0] = new ColumnDescriptor("SubjectId", Integer.class); - xlCols[1] = new ColumnDescriptor("Cohort", String.class); - xlCols[2] = new ColumnDescriptor("StartDate", Date.class); - - MapArrayExcelWriter xlWriter = new MapArrayExcelWriter(participantGroup, xlCols); - xlWriter.setHeaders(Arrays.asList("#Update the SubjectId column of this spreadsheet to the identifiers used when sending a sample to labs", "#")); - xlWriter.renderWorkbook(response); - } - } - - @RequiresPermission(ReadPermission.class) - public static class GetStudyDesigns extends ReadOnlyApiAction - { - @Override - public ApiResponse execute(GetStudyDesignsForm getStudyDesignsForm, BindException errors) throws Exception - { - JSONArray jsonDesigns = new JSONArray(); - StudyDesignInfo[] designs; - if (getStudyDesignsForm.isIncludeSubfolders()) - designs = StudyDesignManager.get().getStudyDesignsForAllFolders(getUser(), getContainer()); - else - designs = StudyDesignManager.get().getStudyDesigns(getContainer()); - for (StudyDesignInfo info : designs) - { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("publicRevision", info.getPublicRevision()); - jsonObject.put("sourceContainer", containerJSON(info.getSourceContainer())); - jsonObject.put("label", info.getLabel()); - jsonObject.put("studyId", info.getStudyId()); - jsonObject.put("active", info.isActive()); - jsonObject.put("container", containerJSON(info.getContainer())); - jsonObject.put("studyDefinition", JSONSerializer.toJSON(StudyDesignManager.get().getGWTStudyDefinition(getUser(), getContainer(), info))); - jsonDesigns.put(jsonObject); - } - - ApiJsonWriter writer = new ApiJsonWriter(getViewContext().getResponse()); - writer.writeResponse(new ApiSimpleResponse("studyDesigns", jsonDesigns)); - return null; - } - - JSONObject containerJSON(Container c) - { - JSONObject j = new JSONObject(); - - j.put("id", c.getId()); - j.put("path", c.getPath()); - j.put("name", c.getName()); - - return j; - } - } - - public static class GetStudyDesignsForm - { - private boolean _includeSubfolders; - - public boolean isIncludeSubfolders() - { - return _includeSubfolders; - } - - public void setIncludeSubfolders(boolean includeSubfolders) - { - _includeSubfolders = includeSubfolders; - } - } - - @SuppressWarnings("unused") // Invoked from createRepositoryWizard.jsp - @RequiresPermission(ReadPermission.class) - public class GetSpecimenExcelAction extends ExportAction - { - @Override - public void export(CreateRepositoryForm form, HttpServletResponse response, BindException errors) - { - //Search for a template in all folders up to root. - SpecimenMigrationService sms = SpecimenMigrationService.get(); - if (null != sms) - { - List> defaultSpecimens = StudyDesignManager.get().generateSampleList(getStudyDefinition(form), getParticipants(), form.getBeginDate()); - sms.exportSpecimens(getContainer(), getUser(), defaultSpecimens, TimepointType.DATE, "Subject", response); - } - } - } - - @SuppressWarnings("unchecked") - @RequiresPermission(AdminPermission.class) - public class CreateRepositoryAction extends FormViewAction - { - private String _titleForNav; - private int _studyId; - private StudyDesignInfo _info; - private ActionURL _successURL; - - @Override - public void validateCommand(CreateRepositoryForm form, Errors errors) - { - _studyId = form.getStudyId(); - _info = StudyDesignManager.get().getStudyDesign(getContainer(), _studyId); - - if (null == _info) - errors.reject(SpringActionController.ERROR_MSG, "Couldn't find study with id " + form.getStudyId()); - - form.setMessage(null); //We're reusing the form, so reset the message. - setWizardStep(form, _info); //Make sure we are not in some weird back/forward state - - _titleForNav = form.getWizardStep().getTitle(); - if (_titleForNav == null) - _titleForNav = form.getStudyName(); - } - - @Override - public boolean handlePost(CreateRepositoryForm form, BindException errors) throws Exception - { - //Wizard step is the *last* wizard step shown to the user. - //Each method handles the post and sets up the form to render the next wizard step - // or re-render same step if errors occurred - switch(form.getWizardStep()) - { - case CONFIRM: - //Put visitids back on uploaded participant info... - List> participantMaps = new ArrayList<>(getParticipants().size()); - for (int i = 0; i < getParticipants().size(); i++) - { - HashMap newMap = new HashMap<>(getParticipants().get(i)); - newMap.put("Date", newMap.get("StartDate")); //Date of demographic data *is* StartDate by default - newMap.put(SOURCE_LSID_PROPERTY_NAME, null); - participantMaps.add(newMap); - } - Study study = StudyDesignManager.get().generateStudyFromDesign(getUser(), ContainerManager.getForId(form.getParentFolderId()), - form.getFolderName(), form.getBeginDate(), form.getSubjectNounSingular(), form.getSubjectNounPlural(), - form.getSubjectColumnName(), _info, participantMaps, getSpecimens()); - _successURL = urlProvider(ProjectUrls.class).getStartURL(study.getContainer()); - return true; - } - return false; - } - - @Override - public URLHelper getSuccessURL(CreateRepositoryForm createRepositoryForm) - { - return _successURL; - } - - @Override - public ModelAndView getView(CreateRepositoryForm form, boolean reshow, BindException errors) throws Exception - { - if (_info == null) - { - _studyId = form.getStudyId(); - _info = StudyDesignManager.get().getStudyDesign(getContainer(), _studyId); - } - StudyDesignVersion version = StudyDesignManager.get().getStudyDesignVersion(_info.getContainer(), _info.getStudyId()); - GWTStudyDefinition def = XMLSerializer.fromXML(version.getXML(), getUser(), getContainer()); - - //Wizard step is the *last* wizard step shown to the user. - //Each method handles the post and sets up the form to render the next wizard step - // or re-render same step if errors occurred - switch(form.getWizardStep()) - { - case INIT: - //We keep the same form instance across posts except if we start new wizard - form = new CreateRepositoryForm(); - form.setStudyId(_studyId); - form.setParentFolderId(getContainer().getId()); - form.setBeginDate(new Date()); - form.setWizardStepNumber(WizardStep.PICK_FOLDER.getNumber()); - form.setStudyName(_info.getLabel()); - form.setFolderName(_info.getLabel()); - form.setSubjectNounSingular(def.getAnimalSpecies()); - form.setSubjectNounPlural(def.getAnimalSpecies() + "s"); - form.setSubjectColumnName(def.getAnimalSpecies() + "Id"); - setParticipants(null); - setSpecimens(null); - break; - case PICK_FOLDER: - pickFolder(form); - break; - case SHOW_PARTICIPANTS: - showParticipants(form); - break; - case UPLOAD_PARTICIPANTS: - uploadParticipants(form); - break; - case SHOW_SAMPLES: - showSamples(form); - break; - case UPLOAD_SAMPLES: - handleUploadSamples(form); - break; - } - return new JspView<>("/org/labkey/study/designer/view/createRepositoryWizard.jsp", form); - } - - @Override - public void addNavTrail(NavTree root) - { - root.addChild("Create Study Folder: " + _titleForNav); - } - } - - - private void setWizardStep(CreateRepositoryForm form, StudyDesignInfo info) - { - //Now see if the study already exists. - if (info.isActive()) - { - throw new RedirectException(urlProvider(ProjectUrls.class).getStartURL(info.getContainer())); - } - - //Make sure we haven't done some crazy back/forward thing - int stepNumber = form.getWizardStep().getNumber(); - if (null == form.getStudyName() || - "".equals(form.getStudyName()) || - null == form.getParentFolderId()|| - null == getStudyDefinition(form)) - { - form.setWizardStep(WizardStep.INIT); - return; - } - Container studyFolder = ContainerManager.getForId(form.getParentFolderId()).getChild(form.getFolderName()); - if (null != studyFolder && null != BaseStudyController.getStudy(studyFolder)) - { - form.setMessage("Folder already exists"); - form.setWizardStep(WizardStep.PICK_FOLDER); - return; - } - if (stepNumber > WizardStep.UPLOAD_PARTICIPANTS.getNumber() && null == getParticipants()) - { - form.setWizardStep(WizardStep.SHOW_PARTICIPANTS); - return; - } - if (stepNumber > WizardStep.UPLOAD_SAMPLES.getNumber() && null == getSpecimens()) - { - form.setWizardStep(WizardStep.SHOW_SAMPLES); - } - } - - private void pickFolder(CreateRepositoryForm form) - { - String folderName = StringUtils.trimToNull(form.getFolderName()); - Container container = getContainer(); - String message; - if (null == folderName) - form.setMessage("Please set a folder name."); - else if (null == form.getBeginDate()) - { - form.setMessage("Please enter a date in the format yyyy-MM-dd."); - form.setBeginDate(new Date()); - } - else if (container.hasChild(folderName) && null != BaseStudyController.getStudy(container.getChild(folderName))) - form.setMessage(container.getName() + " already has a child named " + folderName + " containing a study."); - else if (null != (message = StudyService.get().getSubjectColumnNameValidationErrorMessage(getContainer(), form.getSubjectColumnName()))) - form.setMessage(message); - else if (null != (message = StudyService.get().getSubjectNounSingularValidationErrorMessage(getContainer(), form.getSubjectNounSingular()))) - form.setMessage(message); - else - { - GWTStudyDefinition def = getStudyDefinition(form); - List> participantDataset = StudyDesignManager.get().generateParticipantDataset(getUser(), def); - setParticipants(participantDataset); - form.setWizardStep(WizardStep.SHOW_PARTICIPANTS); - } - } - - @SuppressWarnings("unchecked") - private void showParticipants(CreateRepositoryForm form) throws IOException - { - if (null != form.getParticipantTSV()) - { - TabLoader tl = new TabLoader(form.getParticipantTSV(), true); - setParticipants(tl.load()); - } - if (form.isUploadParticipants()) - uploadParticipants(form); - } - - @SuppressWarnings("unchecked") - private void uploadParticipants(CreateRepositoryForm form) - throws IOException - { - //Parse and validate uploaded participant info - if (null == StringUtils.trimToNull(form.getParticipantTSV())) - { - form.setMessage("Please provide participant information."); - return; - } - TabLoader loader = new TabLoader(form.getParticipantTSV(), true); - fixupParticipantCols(loader); - List errors = new ArrayList<>(); - Set participants = new HashSet<>(); - Map cohortCounts = new CaseInsensitiveHashMap<>(); - GWTStudyDefinition def = getStudyDefinition(form); - for (GWTCohort group : def.getGroups()) - cohortCounts.put(group.getName(), 0); - - List> rows = loader.load(); - if (rows == null || rows.isEmpty()) - { - form.setMessage("Information for at least one participant is required."); - return; - } - - setParticipants(rows); - int rowNum = 1; - for (Map row : rows) - { - String cohort = (String) row.get("Cohort"); - String participant = (String) row.get("ParticipantId"); - Date startDate = (Date) row.get("StartDate"); - if (!form.isIgnoreWarnings() && null == cohort) - { - errors.add("Warning, Row " + rowNum + " no cohort is listed."); - form.setContainsWarnings(true); - } - else if (!form.isIgnoreWarnings() && !cohortCounts.containsKey(cohort)) - { - errors.add("Warning, Row " + rowNum + " cohort " + cohort + " is not listed in study definition."); - form.setContainsWarnings(true); - } - else - cohortCounts.put(cohort, (null == cohortCounts.get(cohort) ? 0 : cohortCounts.get(cohort).intValue()) + 1); - - if (null == participant) - errors.add("Error, Row " + rowNum + " no subject is listed."); - else if (participants.contains(participant)) - errors.add("Error, Row " + rowNum + " subject is listed more than once"); - else - participants.add(participant); - - if (null == startDate) - errors.add("Error, Row " + rowNum + " StartDate is not provided."); - - if (errors.size() >= 3) - break; - - rowNum++; - } - if (!form.isIgnoreWarnings() && errors.size() == 0) - for (GWTCohort group : def.getGroups()) - { - if (cohortCounts.get(group.getName()).intValue() < group.getCount()) - { - errors.add("Warning: not enough subjects for cohort " + group.getName() + " expected " + group.getCount() + " found " + cohortCounts.get(group.getName())); - form.setContainsWarnings(true); - } - } - - if (errors.size() > 0 && !form.isIgnoreWarnings()) - { - StringBuilder sb = new StringBuilder(); - for (String error : errors) - sb.append(error).append("\n"); - - form.setMessage(sb.toString()); - } - else - { - form.setWizardStep(WizardStep.SHOW_SAMPLES); - } - } - - private static void fixupParticipantCols(TabLoader loader) throws IOException - { - ColumnDescriptor[] loaderCols = loader.getColumns(); - Map colMap = new CaseInsensitiveHashMap<>(); - for (ColumnDescriptor col : PARTICIPANT_COLS) - colMap.put(col.name, col); - colMap.put("ptid", colMap.get("ParticipantId")); - colMap.put("SubjectId", colMap.get(SpecimenMigrationService.PARTICIPANT_ID)); - - ColumnDescriptor[] newCols = new ColumnDescriptor[loaderCols.length]; - for (int i = 0; i < loaderCols.length; i++) - { - if (colMap.containsKey(loaderCols[i].name)) - newCols[i] = colMap.get(loaderCols[i].name); - else - newCols[i] = loaderCols[i]; - } - loader.setColumns(newCols); - } - - private static StudyDesignInfo getTemplateInfo(User u, Container c) throws Exception - { - StudyDesignInfo info = StudyDesignManager.get().getStudyDesign(c.getProject(), TEMPLATE_NAME); - if (null == info) - { - getTemplate(u, c); - info = StudyDesignManager.get().getStudyDesign(c.getProject(), TEMPLATE_NAME); - } - return info; - } - - @SuppressWarnings("unchecked") - private void showSamples(CreateRepositoryForm form) throws IOException - { - if (form.isUploadSpecimens()) - { - if (null != form.getSpecimenTSV()) - { - //Handle back->forward case by reloading - TabLoader tl = new TabLoader(form.getSpecimenTSV(), true); - setSpecimens(tl.load()); - } - handleUploadSamples(form); - } - else - { - if (null != form.getSpecimenTSV()) //Reset to autogenerated list - setSpecimens(StudyDesignManager.get().generateSampleList(getStudyDefinition(form), getParticipants(), form.getBeginDate())); - form.setWizardStep(WizardStep.CONFIRM); - } - } - - @SuppressWarnings("unchecked") - private void handleUploadSamples(CreateRepositoryForm form) throws IOException - { - SpecimenMigrationService sms = SpecimenMigrationService.get(); - if (null != sms) - { - Set errors = new LinkedHashSet<>(); - String specimenTSV = StringUtils.trimToNull(form.getSpecimenTSV()); - if (null == specimenTSV) - { - form.setMessage("Please provide specimen information."); - return; - } - TabLoader loader = new TabLoader(specimenTSV, true); - Map columnAliases = new HashMap<>(); - Map labels = new HashMap<>(); - //Make sure we accept the labels - for (Map.Entry entry : sms.getColumnLabelMap(getContainer(), getUser()).entrySet()) - { - columnAliases.put(entry.getValue(), entry.getKey()); - labels.put(entry.getKey(), entry.getValue()); - } - - //And a few more aliases - columnAliases.put("ParticipantId", SpecimenMigrationService.PARTICIPANT_ID); - columnAliases.put("Date", SpecimenMigrationService.DRAW_TIMESTAMP); - columnAliases.put("Subject", SpecimenMigrationService.PARTICIPANT_ID); - - //Remember whether we used a different header so we can put up error messages that make sense - for (ColumnDescriptor c : loader.getColumns()) - { - if (columnAliases.containsKey(c.name)) - { - labels.put(columnAliases.get(c.name), c.name); - c.name = columnAliases.get(c.name); - } - else - labels.put(c.name, c.name); - } - sms.fixupSpecimenColumns(getContainer(), getUser(), loader); - - List> specimenRows = loader.load(); - setSpecimens(specimenRows); - Set participants = new HashSet<>(); - int rowNum = 1; - for (Map row : specimenRows) - { - if (row.get(SpecimenMigrationService.VIAL_ID) == null && row.get(SpecimenMigrationService.SAMPLE_ID) == null) - errors.add("Error, Row " + rowNum + " must provide a sample or vial ID."); - - String participant = (String) row.get(SpecimenMigrationService.PARTICIPANT_ID); - if (null == participant) - errors.add("Error, Row " + rowNum + " field " + labels.get(SpecimenMigrationService.PARTICIPANT_ID) + " is not supplied"); - else - participants.add(participant); - - for (String col : PageFlowUtil.set(SpecimenMigrationService.SAMPLE_ID, SpecimenMigrationService.DRAW_TIMESTAMP)) - if (null == row.get(col)) - errors.add("Error, Row " + rowNum + " does not contain a value for field " + (labels.containsKey(col) ? labels.get(col) : col)); - - if (errors.size() >= 3) - break; - - rowNum++; - } - if (!form.isIgnoreWarnings()) - { - int nParticipantsExpected = 0; - for (GWTCohort cohort : getStudyDefinition(form).getGroups()) - nParticipantsExpected += cohort.getCount(); - - if (participants.size() != nParticipantsExpected) - errors.add("Warning, Expected samples for " + nParticipantsExpected + " subjects, received samples for " + participants); - - form.setContainsWarnings(true); - } - if (!errors.isEmpty()) - { - StringBuilder sb = new StringBuilder(); - for (String e : errors) - sb.append(e).append("\n"); - - form.setMessage(sb.toString()); - } - else - form.setWizardStep(WizardStep.CONFIRM); - } - } - - public static GWTStudyDefinition getStudyDefinition(CreateRepositoryForm form, User user, Container container) - { - StudyDesignInfo info = StudyDesignManager.get().getStudyDesign(container, form.getStudyId()); - if (info == null) - throw new IllegalStateException("Could not find StudyDesignInfo for studyId " + form.getStudyId()); - return StudyDesignManager.get().getGWTStudyDefinition(user, container, info); - } - - private GWTStudyDefinition getStudyDefinition(CreateRepositoryForm form) - { - return getStudyDefinition(form, getUser(), getContainer()); - } - - @SuppressWarnings("unchecked") - public static List> getParticipants() - { - return (List>)HttpView.currentContext().getSession().getAttribute(PARTICIPANT_KEY); - } - - private void setParticipants(List> participants) - { - HttpSession session = HttpView.currentContext().getSession(); - if (participants == null) - { - session.removeAttribute(PARTICIPANT_KEY); - return; - } - session.setAttribute(PARTICIPANT_KEY, participants); - } - - @SuppressWarnings("unchecked") - public static List> getSpecimens() - { - return (List>)HttpView.currentContext().getSession().getAttribute(SPECIMEN_KEY); - } - - private void setSpecimens(List> specimens) - { - HttpSession session = HttpView.currentContext().getSession(); - if (specimens == null) - { - session.removeAttribute(SPECIMEN_KEY); - return; - } - session.setAttribute(SPECIMEN_KEY, specimens); - } - - public static synchronized GWTStudyDefinition getTemplate(User u, Container c) throws Exception - { - StudyDesignInfo info = StudyDesignManager.get().getStudyDesign(c.getProject(), TEMPLATE_NAME); - if (null != info) - { - StudyDesignVersion version = StudyDesignManager.get().getStudyDesignVersion(c.getProject(), info.getStudyId()); - GWTStudyDefinition def = XMLSerializer.fromXML(version.getXML(), u, c); - def.setCavdStudyId(version.getStudyId()); - def.setRevision(version.getRevision()); - return def; - } - - GWTStudyDefinition def = GWTStudyDefinition.getDefaultTemplate(); - def.setStudyName(TEMPLATE_NAME); - StudyDesignVersion version = new StudyDesignVersion(); - version.setContainer(c.getProject()); - version.setLabel(TEMPLATE_NAME); - version.setDescription("Template used for creating new studies"); - version.setXML(XMLSerializer.toXML(def).toString()); - version = StudyDesignManager.get().saveStudyDesign(u, c.getProject(), version); - - def.setRevision(version.getRevision()); - def.setCavdStudyId(version.getStudyId()); - - return def; - } - - public static class CreateRepositoryForm - { - private int wizardStepNumber; - private int studyId; - private String studyName; - private String folderName; - private String message; - private boolean uploadParticipants; - private boolean uploadSpecimens; - private String participantTSV; - private String specimenTSV; - private String parentFolderId; - private Date beginDate; - private boolean ignoreWarnings; - private boolean containsWarnings; - private String subjectNounSingular; - private String subjectNounPlural; - private String subjectColumnName; - - public int getStudyId() - { - return studyId; - } - - public void setStudyId(int studyId) - { - this.studyId = studyId; - } - - public String getStudyName() - { - return studyName; - } - - public void setStudyName(String studyName) - { - this.studyName = studyName; - } - - public int getWizardStepNumber() - { - return wizardStepNumber; - } - - public void setWizardStepNumber(int wizardStepNumber) - { - this.wizardStepNumber = wizardStepNumber; - } - - public String getMessage() - { - return message; - } - - public void setMessage(String message) - { - this.message = message; - } - - public String getFolderName() - { - return folderName; - } - - public void setFolderName(String folderName) - { - this.folderName = folderName; - } - - public boolean isUploadParticipants() - { - return uploadParticipants; - } - - public void setUploadParticipants(boolean uploadParticipants) - { - this.uploadParticipants = uploadParticipants; - } - - public String getParticipantTSV() - { - return participantTSV; - } - - public void setParticipantTSV(String participantTSV) - { - this.participantTSV = participantTSV; - } - - public boolean isUploadSpecimens() - { - return uploadSpecimens; - } - - public void setUploadSpecimens(boolean uploadSpecimens) - { - this.uploadSpecimens = uploadSpecimens; - } - - public String getSpecimenTSV() - { - return specimenTSV; - } - - public void setSpecimenTSV(String specimenTSV) - { - this.specimenTSV = specimenTSV; - } - - public WizardStep getWizardStep() - { - return WizardStep.fromNumber(getWizardStepNumber()); - } - - public void setWizardStep(WizardStep wizardStep) - { - wizardStepNumber = wizardStep.getNumber(); - } - - public String getParentFolderId() - { - return parentFolderId; - } - - public void setParentFolderId(String parentFolderId) - { - this.parentFolderId = parentFolderId; - } - - public void setBeginDate(Date beginDate) - { - this.beginDate = beginDate; - } - - public Date getBeginDate() - { - return beginDate; - } - - public boolean isIgnoreWarnings() - { - return ignoreWarnings; - } - - public void setIgnoreWarnings(boolean ignoreWarnings) - { - this.ignoreWarnings = ignoreWarnings; - } - - public boolean isContainsWarnings() - { - return containsWarnings; - } - - public void setContainsWarnings(boolean containsWarnings) - { - this.containsWarnings = containsWarnings; - } - - public String getSubjectNounSingular() - { - return subjectNounSingular; - } - - public void setSubjectNounSingular(String subjectNounSingular) - { - this.subjectNounSingular = subjectNounSingular; - } - - public String getSubjectNounPlural() - { - return subjectNounPlural; - } - - public void setSubjectNounPlural(String subjectNounPlural) - { - this.subjectNounPlural = subjectNounPlural; - } - - public String getSubjectColumnName() - { - return subjectColumnName; - } - - public void setSubjectColumnName(String subjectColumnName) - { - this.subjectColumnName = subjectColumnName; - } - } - - public static class StudyDesignForm - { - private int studyId; - private int revision; - private String finishURL; - private boolean edit; - private String panel; - - public int getRevision() - { - return revision; - } - - public void setRevision(int revision) - { - this.revision = revision; - } - - public int getStudyId() - { - return studyId; - } - - public void setStudyId(int studyId) - { - this.studyId = studyId; - } - - public boolean isEdit() - { - return edit; - } - - public void setEdit(boolean edit) - { - this.edit = edit; - } - - public String getFinishURL() - { - return finishURL; - } - - public void setFinishURL(String finishURL) - { - this.finishURL = finishURL; - } - - public String getPanel() - { - return panel; - } - - public void setPanel(String panel) - { - this.panel = panel; - } - } -} diff --git a/study/src/org/labkey/study/designer/JSONSerializer.java b/study/src/org/labkey/study/designer/JSONSerializer.java deleted file mode 100644 index ed384006c34..00000000000 --- a/study/src/org/labkey/study/designer/JSONSerializer.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 2009-2016 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.labkey.study.designer; - -import gwt.client.org.labkey.study.designer.client.model.GWTAdjuvant; -import gwt.client.org.labkey.study.designer.client.model.GWTAntigen; -import gwt.client.org.labkey.study.designer.client.model.GWTAssayDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTAssayNote; -import gwt.client.org.labkey.study.designer.client.model.GWTAssaySchedule; -import gwt.client.org.labkey.study.designer.client.model.GWTCohort; -import gwt.client.org.labkey.study.designer.client.model.GWTImmunization; -import gwt.client.org.labkey.study.designer.client.model.GWTImmunizationSchedule; -import gwt.client.org.labkey.study.designer.client.model.GWTImmunogen; -import gwt.client.org.labkey.study.designer.client.model.GWTSampleMeasure; -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTTimepoint; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.xmlbeans.XmlError; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; -import org.json.JSONObject; -import org.labkey.study.xml.Adjuvant; -import org.labkey.study.xml.AdjuvantRef; -import org.labkey.study.xml.Antigen; -import org.labkey.study.xml.AssayEvent; -import org.labkey.study.xml.AssaySchedule; -import org.labkey.study.xml.Cohort; -import org.labkey.study.xml.ImmunizationEvent; -import org.labkey.study.xml.Immunogen; -import org.labkey.study.xml.ImmunogenRef; -import org.labkey.study.xml.SampleMeasure; -import org.labkey.study.xml.StudyDesign; -import org.labkey.study.xml.StudyDesignDocument; -import org.labkey.study.xml.Timepoint; - -import java.util.ArrayList; -import java.util.List; - -public class JSONSerializer -{ - private static Logger _log = LogManager.getLogger(XMLSerializer.class); - - public static JSONObject toJSON(String xml) - { - - StudyDesignDocument doc; - try - { - doc = StudyDesignDocument.Factory.parse(xml); - } catch (XmlException e) - { - _log.error(e); - throw new RuntimeException(e); - } - - StudyDesign xdesign = doc.getStudyDesign(); - assert validate(doc); - - JSONObject j = new JSONObject(); - j.put("name", xdesign.getName()); - j.put("grantName", xdesign.getGrantName()); - j.put("investigator", xdesign.getInvestigator()); - j.put("animalSpecies", xdesign.getAnimalSpecies()); - if (xdesign.isSetDescription()) - j.put("description", xdesign.getDescription()); - - for (Immunogen immunogen : xdesign.getImmunogens().getImmunogenArray()) - { - JSONObject jimmunogen = new JSONObject(); - jimmunogen.put("name", immunogen.getName()); - jimmunogen.put("dose", immunogen.getDose()); - jimmunogen.put("type", immunogen.getType()); - jimmunogen.put("admin", immunogen.getAdmin()); - - GWTImmunogen gimmunogen = new GWTImmunogen(immunogen.getName(), immunogen.getDose(), immunogen.getType(), immunogen.getAdmin()); - for (Antigen antigen : immunogen.getAntigens().getAntigenArray()) - { - JSONObject jantigen = new JSONObject(); - jantigen.put("name", antigen.getName()); - jantigen.put("gene", antigen.getGene()); - jantigen.put("subtype", antigen.getSubtype()); - jantigen.put("genBankId", antigen.getGenBankId()); - jantigen.put("sequence", antigen.getSequence()); - jimmunogen.append("antigens", jantigen); - } - - j.append("immunogens", jimmunogen); - - } - - for (Adjuvant adjuvant : xdesign.getAdjuvants().getAdjuvantArray()) - { - JSONObject jadjuvant = new JSONObject(); - jadjuvant.put("name", adjuvant.getName()); - jadjuvant.put("dose", adjuvant.getDose()); - jadjuvant.put("admin", adjuvant.getAdmin()); - j.append("adjuvants", jadjuvant); - } - - - for (Cohort cohort : xdesign.getCohorts().getCohortArray()) - { - JSONObject jcohort = new JSONObject(); - jcohort.put("name", cohort.getName()); - jcohort.put("count", cohort.getCount()); - j.append("cohorts", jcohort); - } - - - AssaySchedule xAssaySchedule = xdesign.getAssaySchedule(); - JSONObject jAssaySchedule = new JSONObject(); - j.put("assaySchedule", jAssaySchedule); - if (null != xAssaySchedule.getDescription()) - jAssaySchedule.put("description", xAssaySchedule.getDescription()); - - - for (AssayEvent evt : xAssaySchedule.getAssayEventArray()) - { - Timepoint tp = evt.getTimepoint(); - JSONObject jAssay = new JSONObject(); - jAssay.put("timepoint", createTimepoint(tp)); - jAssay.put("name", evt.getAssayName()); - jAssay.put("sampleMeasure", createSampleMeasure(evt.getSampleMeasure())); - - jAssaySchedule.append("assays", jAssay); - } - - GWTImmunizationSchedule gImmunizationSchedule = new GWTImmunizationSchedule(); - for (ImmunizationEvent evt : xdesign.getImmunizationSchedule().getImmunizationEventArray()) - { - - Timepoint tp = evt.getTimepoint(); - GWTTimepoint.Unit unit = GWTTimepoint.Unit.fromString(tp.getDisplayUnit()); - GWTTimepoint gtp = new GWTTimepoint(tp.getName(), tp.getDays() / unit.daysPerUnit, GWTTimepoint.Unit.fromString(tp.getDisplayUnit())); - JSONObject immunization = new JSONObject(); - for (ImmunogenRef immunogenRef : evt.getImmunization().getImmunogenRefArray()) - immunization.append("immunogens", immunogenRef.getName()); - for (AdjuvantRef adjuvantRef : evt.getImmunization().getAdjuvantRefArray()) - immunization.append("adjuvants", adjuvantRef.getName()); - - immunization.put("groupName", evt.getGroupName()); - immunization.put("timepoint", createTimepoint(evt.getTimepoint())); - - j.append("immunizations", immunization); - } - - return j; - } - - public static JSONObject toJSON(GWTStudyDefinition def) - { - try - { - JSONObject j = new JSONObject(); - j.put("grantName", def.getGrant()); - j.put("investigator", def.getInvestigator()); - j.put("name", def.getStudyName()); - j.put("animalSpecies", def.getAnimalSpecies()); - if (null != def.getDescription()) - j.put("description", def.getDescription()); - - for (int i = 0; i < def.getImmunogens().size(); i++) - { - GWTImmunogen gImmunogen = def.getImmunogens().get(i); - - JSONObject jImmunogen = new JSONObject(); - jImmunogen.put("admin", gImmunogen.getAdmin()); - jImmunogen.put("name", gImmunogen.getName()); - jImmunogen.put("dose", gImmunogen.getDose()); - jImmunogen.put("type", gImmunogen.getType()); - - for (Object o : gImmunogen.getAntigens()) - { - GWTAntigen gAntigen = (GWTAntigen) o; - JSONObject jAntigen = new JSONObject(); - jAntigen.put("gene", gAntigen.getGene()); - jAntigen.put("name", gAntigen.getName()); - if (null != gAntigen.getSequence()) - jAntigen.put("sequence", gAntigen.getSequence()); - if (null != gAntigen.getGenBankId()) - jAntigen.put("genBankId", gAntigen.getGenBankId()); - jAntigen.put("subtype", gAntigen.getSubtype()); - - jImmunogen.append("antigens", jAntigen); - } - j.append("immunogens", jImmunogen); - } - - for (int i = 0; i < def.getAdjuvants().size(); i++) - { - GWTAdjuvant gAdjuvant = def.getAdjuvants().get(i); - JSONObject jAdjuvant = new JSONObject(); - jAdjuvant.put("admin", gAdjuvant.admin); - jAdjuvant.put("name", gAdjuvant.getName()); - jAdjuvant.put("dose", gAdjuvant.getDose()); - j.append("adjuvants", jAdjuvant); - } - - - for (int i = 0; i < def.getGroups().size(); i++) - { - GWTCohort gwtCohort = def.getGroups().get(i); - JSONObject jCohort = new JSONObject(); - jCohort.put("name", gwtCohort.getName()); - jCohort.put("count", gwtCohort.getCount()); - j.append("cohorts", jCohort); - } - - GWTImmunizationSchedule gSchedule = def.getImmunizationSchedule(); - for (GWTCohort gCohort : def.getGroups()) - { - for (GWTTimepoint gtp : gSchedule.getTimepoints()) - { - GWTImmunization gImmunization = gSchedule.getImmunization(gCohort, gtp); - if (null != gImmunization) - { - JSONObject jevt = new JSONObject(); - jevt.put("groupName", gCohort.getName()); - jevt.put("timepoint", createTimepoint(gtp)); - for (GWTImmunogen gImmunogen : gImmunization.immunogens) - jevt.append("immunogens", gImmunogen.getName()); - - for (GWTAdjuvant gAdjuvant : gImmunization.adjuvants) - jevt.append("adjuvants", gAdjuvant.getName()); - - j.append("immunizations", jevt); - } - } - } - - JSONObject jAssaySchedule = new JSONObject(); - GWTAssaySchedule gAssaySchedule = def.getAssaySchedule(); - if (null != gAssaySchedule.getDescription()) - jAssaySchedule.put("description", gAssaySchedule.getDescription()); - - - for (GWTAssayDefinition gwtAssayDefinition : gAssaySchedule.getAssays()) - { - boolean wasArrayEmitted = false; - for (GWTTimepoint gwtTimepoint : gAssaySchedule.getTimepoints()) - { - GWTAssayNote gwtAssayNote = gAssaySchedule.getAssayPerformed(gwtAssayDefinition, gwtTimepoint); - if (null != gwtAssayNote) - { - JSONObject jAssay = new JSONObject(); - jAssay.put("name", gwtAssayDefinition.getAssayName()); - jAssay.put("timepoint", createTimepoint(gwtTimepoint)); - jAssay.put("sampleMeasure", createSampleMeasure(gwtAssayNote.getSampleMeasure())); - jAssay.put("lab", gwtAssayDefinition.getLab()); - jAssaySchedule.append("assays", jAssay); - wasArrayEmitted = true; - } - } - if (!wasArrayEmitted) - { - JSONObject jAssay = new JSONObject(); - jAssay.put("name", gwtAssayDefinition.getAssayName()); - jAssay.put("lab", gwtAssayDefinition.getLab()); - jAssaySchedule.append("assays", jAssay); - } - } - j.put("assaySchedule", jAssaySchedule); - - return j; - - } - catch (Exception e) - { - _log.error(e); - throw new RuntimeException(e); - } - } - - - static JSONObject createJSONSampleMeasure(SampleMeasure measure, GWTStudyDefinition parent) - { - JSONObject jSampleMeasure = new JSONObject(); - jSampleMeasure.put("amount", measure.getAmount()); - jSampleMeasure.put("type", measure.getType()); - jSampleMeasure.put("unit", measure.getUnit()); - - return jSampleMeasure; - } - - static JSONObject createTimepoint(GWTTimepoint gtp) - { - JSONObject tp = new JSONObject(); - tp.put("days", gtp.getDays()); - tp.put("displayUnit", gtp.getUnit().toString()); - if (null != gtp.getName()) - tp.put("name", gtp.getName()); - else - tp.put("name", gtp.toString()); - - return tp; - } - - static JSONObject createTimepoint(Timepoint tp) - { - - GWTTimepoint.Unit unit = GWTTimepoint.Unit.fromString(tp.getDisplayUnit()); - GWTTimepoint gtp = new GWTTimepoint(tp.getName(), tp.getDays()/unit.daysPerUnit, unit); - return createTimepoint(gtp); - } - - static JSONObject createSampleMeasure(GWTSampleMeasure gwtSampleMeasure) - { - JSONObject sm = new JSONObject(); - sm.put("type", gwtSampleMeasure.getType()); - sm.put("amount", gwtSampleMeasure.getAmount()); - sm.put("unit", gwtSampleMeasure.getUnit()); - - return sm; - } - - - static JSONObject createSampleMeasure(SampleMeasure sampleMeasure) - { - JSONObject sm = new JSONObject(); - sm.put("type", sampleMeasure.getType()); - sm.put("amount", sampleMeasure.getAmount()); - sm.put("unit", sampleMeasure.getUnit()); - - return sm; - } - - static GWTImmunogen findImmunogen(String name, List immunogens) - { - for (GWTImmunogen i : immunogens) - if (i.getName().equals(name)) - return i; - - return null; - } - - static GWTAdjuvant findAdjuvant(String name, List adjuvants) - { - for (GWTAdjuvant i : adjuvants) - if (i.getName().equals(name)) - return i; - - return null; - } - - static GWTCohort findCohort(String name, List cohorts) - { - for (GWTCohort c : cohorts) - if (c.getName().equals(name)) - return c; - - return null; - } - - static boolean validate(StudyDesignDocument doc) - { - XmlOptions opts = new XmlOptions(); - ArrayList errors = new ArrayList(); - opts.setErrorListener(errors); - boolean valid = doc.validate(opts); - return valid; - } -} - diff --git a/study/src/org/labkey/study/designer/SaveException.java b/study/src/org/labkey/study/designer/SaveException.java deleted file mode 100644 index fee32f7d69b..00000000000 --- a/study/src/org/labkey/study/designer/SaveException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2008 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.labkey.study.designer; - -/** - * User: jgarms - * Date: Aug 15, 2008 - * Time: 10:29:23 AM - */ -public class SaveException extends Exception -{ - public SaveException(String message) - { - super(message); - } -} diff --git a/study/src/org/labkey/study/designer/StudyDefinitionServiceImpl.java b/study/src/org/labkey/study/designer/StudyDefinitionServiceImpl.java deleted file mode 100644 index d02c06a5911..00000000000 --- a/study/src/org/labkey/study/designer/StudyDefinitionServiceImpl.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Copyright (c) 2008-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.study.designer; - -import gwt.client.org.labkey.study.designer.client.StudyDefinitionService; -import gwt.client.org.labkey.study.designer.client.model.GWTAssayDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTCohort; -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDesignVersion; -import gwt.client.org.labkey.study.designer.client.model.GWTTimepoint; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.labkey.api.data.Container; -import org.labkey.api.gwt.server.BaseRemoteService; -import org.labkey.api.query.ValidationException; -import org.labkey.api.reports.model.ViewCategory; -import org.labkey.api.reports.model.ViewCategoryManager; -import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.security.permissions.UpdatePermission; -import org.labkey.api.study.Dataset; -import org.labkey.api.study.StudyService; -import org.labkey.api.study.TimepointType; -import org.labkey.api.study.Visit; -import org.labkey.api.util.UnexpectedException; -import org.labkey.api.view.NotFoundException; -import org.labkey.api.view.UnauthorizedException; -import org.labkey.api.view.ViewContext; -import org.labkey.study.assay.StudyPublishManager; -import org.labkey.study.controllers.designer.DesignerController; -import org.labkey.study.model.CohortImpl; -import org.labkey.study.model.CohortManager; -import org.labkey.study.model.DatasetDefinition; -import org.labkey.study.model.StudyImpl; -import org.labkey.study.model.StudyManager; -import org.labkey.study.model.VisitImpl; -import org.labkey.study.xml.StudyDesignDocument; - -import java.math.BigDecimal; -import java.util.Collections; -import java.util.List; - -/** - * User: Mark Igra - * Date: Feb 14, 2007 - * Time: 9:21:22 PM - */ -public class StudyDefinitionServiceImpl extends BaseRemoteService implements StudyDefinitionService -{ - private static Logger _log = LogManager.getLogger(StudyDefinitionServiceImpl.class); - - public StudyDefinitionServiceImpl(ViewContext context) - { - super(context); - } - - @Override - public GWTStudyDesignVersion save(GWTStudyDefinition def) - { - if (!getContainer().hasPermission(getUser(), UpdatePermission.class)) - { - GWTStudyDesignVersion result = new GWTStudyDesignVersion(); - result.setSaveSuccessful(false); - result.setErrorMessage("You do not have permission to save"); - return result; - } - try - { - syncStudyCohorts(def); - - StudyDesignDocument design = XMLSerializer.toXML(def); - StudyDesignVersion version = new StudyDesignVersion(); - version.setXML(design.toString()); - version.setStudyId(def.getCavdStudyId()); - version.setLabel(def.getStudyName()); - GWTStudyDesignVersion result = StudyDesignManager.get().saveStudyDesign(getUser(), getContainer(), version).toGWTVersion(_context); - result.setSaveSuccessful(true); - return result; - } - catch (SaveException se) - { - GWTStudyDesignVersion result = new GWTStudyDesignVersion(); - result.setSaveSuccessful(false); - result.setErrorMessage(se.getMessage()); - return result; - } - } - - @Override - public GWTStudyDefinition getBlank() - { - try - { - GWTStudyDefinition def = DesignerController.getTemplate(getUser(), getContainer()); - def.setCavdStudyId(0); - def.setRevision(0); - def.setStudyName(null); - - return def; - } - catch (Exception e) - { - throw UnexpectedException.wrap(e); - } - } - - @Override - public GWTStudyDefinition getRevision(int studyId, int revision) - { - try - { - Container container = getContainer(); - StudyDesignVersion version; - if (revision >= 0) - version = StudyDesignManager.get().getStudyDesignVersion(container, studyId, revision); - else - version = StudyDesignManager.get().getStudyDesignVersion(container, studyId); - - if (null == version) - throw new NotFoundException("Protocol " + studyId + (revision >= 0 ? ", Revision " + revision : "") + " not found!"); - - GWTStudyDefinition template = getTemplate(); - GWTStudyDefinition def = XMLSerializer.fromXML(version.getXML(), template.getCavdStudyId() == studyId ? null : template, getUser(), container); - def.setCavdStudyId(version.getStudyId()); - def.setRevision(version.getRevision()); - StudyDesignInfo info = StudyDesignManager.get().getStudyDesign(getContainer(), studyId); - StudyDesignManager.get().mergeStudyProperties(def, info); - return def; - } - catch (Exception e) - { - throw UnexpectedException.wrap(e); - } - } - - @Override - public GWTStudyDefinition getTemplate() - { - try - { - return DesignerController.getTemplate(getUser(), getContainer()); - } - catch (Exception e) - { - throw UnexpectedException.wrap(e); - } - } - - @Override - public GWTStudyDesignVersion[] getVersions(int studyId) - { - StudyDesignVersion[] versions = StudyDesignManager.get().getStudyDesignVersions(getContainer(), studyId); - GWTStudyDesignVersion[] gwtVersions = new GWTStudyDesignVersion[versions.length]; - for (int i = 0; i < versions.length; i++) - gwtVersions[i] = versions[i].toGWTVersion(_context); - - return gwtVersions; - } - - @Override - public GWTStudyDefinition ensureDatasetPlaceholders(GWTStudyDefinition studyDefinition) - { - if (!getContainer().hasPermission(getUser(), AdminPermission.class)) - throw new UnauthorizedException("Only admins can create dataset definitions."); - - StudyImpl study = StudyManager.getInstance().getStudy(getContainer()); - if (null == study) - throw new IllegalStateException("No study found in this folder."); - - int categoryId; - ViewCategory category = ViewCategoryManager.getInstance().ensureViewCategory(getContainer(), getUser(), "Assays"); - categoryId = category.getRowId(); - - for (GWTAssayDefinition assayDefinition : studyDefinition.getAssaySchedule().getAssays()) - { - int dsId = StudyService.get().getDatasetIdByName(getContainer(), assayDefinition.getAssayName()); - if (dsId == -1) - { - DatasetDefinition datasetDefinition = StudyPublishManager.getInstance().createDataset(getUser(), new DatasetDefinition.Builder(assayDefinition.getAssayName()) - .setStudy(study) - .setDemographicData(false) - .setType(Dataset.TYPE_PLACEHOLDER) - .setCategoryId(categoryId)); - datasetDefinition.provisionTable(); - } - } - - return studyDefinition; - } - - @Override - public GWTStudyDefinition createTimepoints(GWTStudyDefinition studyDefinition) - { - if (!getContainer().hasPermission(getUser(), AdminPermission.class)) - throw new UnauthorizedException("Only admins can create timepoints."); - - StudyImpl study = StudyManager.getInstance().getStudy(getContainer()); - if (null == study) - throw new IllegalStateException("No study found in this folder."); - - if (!study.getVisits(Visit.Order.DISPLAY).isEmpty()) - throw new IllegalStateException("There are already timepoints in this study."); - - if (studyDefinition.getAssaySchedule().getTimepoints().isEmpty()) - return studyDefinition; - - //Make sure we're a date type study - study = study.createMutable(); - if (!study.getDatasets().isEmpty()&& study.getTimepointType() != TimepointType.DATE) - { - throw new IllegalStateException("Cannot change timepoint type after datasets already exist"); - } - study.setTimepointType(TimepointType.DATE); - StudyManager.getInstance().updateStudy(getUser(), study); - - List timepoints = studyDefinition.getAssaySchedule().getTimepoints(); - Collections.sort(timepoints); - if (timepoints.get(0).getDays() > 0) - timepoints.add(0, new GWTTimepoint("Study Start", 0, GWTTimepoint.DAYS)); - - //We try to create timepoints that make sense. A week is day-3 to day +3 unless that would overlap - double previousDay = timepoints.get(0).getDays() - 1.0; - for (int timepointIndex = 0; timepointIndex < timepoints.size(); timepointIndex++) - { - GWTTimepoint timepoint = timepoints.get(timepointIndex); - double startDay = timepoints.get(timepointIndex).getDays(); - double endDay = startDay; - double nextDay = timepointIndex + 1 == timepoints.size() ? Double.MAX_VALUE : timepoints.get(timepointIndex + 1).getDays(); - if (timepoint.getUnit().equals(GWTTimepoint.WEEKS)) - { - startDay = Math.max(previousDay + 1, startDay - 3); - endDay = Math.min(nextDay - 1, endDay + 3); - } - else if (timepoint.getUnit().equals(GWTTimepoint.MONTHS)) - { - startDay = Math.max(previousDay + 1, startDay - 15); - endDay = Math.min(nextDay - 1, endDay + 15); - } - VisitImpl visit = new VisitImpl(getContainer(), BigDecimal.valueOf(startDay), BigDecimal.valueOf(endDay), timepoint.toString(), Visit.Type.REQUIRED_BY_TERMINATION); - StudyManager.getInstance().createVisit(study, getUser(), visit); - previousDay = endDay; - } - - return studyDefinition; - } - - @Override - public GWTStudyDefinition createCohorts(GWTStudyDefinition studyDefinition) - { - StudyImpl study = StudyManager.getInstance().getStudy(getContainer()); - if (study == null || studyDefinition.getGroups().size() == 0) - return studyDefinition; - - try - { - // create any cohorts that don't exist or get the cohort RowId if one does exist in the study - for (GWTCohort defGroup : studyDefinition.getGroups()) - { - CohortImpl cohort = CohortManager.getInstance().ensureCohort(study, getUser(), defGroup.getName(), true, defGroup.getCount(), null); - defGroup.setCohortId(cohort.getRowId()); - } - } - catch(ValidationException e) - { - throw UnexpectedException.wrap(e); - } - - return studyDefinition; - } - - private void syncStudyCohorts(GWTStudyDefinition studyDefinition) - { - // first we create study cohorts for any "new" groups/cohorts - createCohorts(studyDefinition); - - StudyImpl study = StudyManager.getInstance().getStudy(getContainer()); - if (study != null && studyDefinition.getGroupsToDelete() != null && !studyDefinition.getGroupsToDelete().isEmpty()) - { - // then we reconcile the list of groups to delete with the full list of study designer groups - for (GWTCohort defGroup : studyDefinition.getGroups()) - { - if (studyDefinition.getGroupsToDelete().contains(defGroup.getName())) - studyDefinition.getGroupsToDelete().remove(defGroup.getName()); - } - - // finally we delete any groups that were removed from the study design and have a corresponding cohort Id - for (String name : studyDefinition.getGroupsToDelete()) - { - CohortImpl cohort = StudyManager.getInstance().getCohortByLabel(getContainer(), getUser(), name); - // don't delete any in-use cohorts from the study - if (cohort != null && !cohort.isInUse()) - StudyManager.getInstance().deleteCohort(cohort); - } - - studyDefinition.clearGroupsToDelete(); - } - } - - @Override - public Boolean hasNewCohorts(GWTStudyDefinition studyDefinition) - { - for (GWTCohort defGroup : studyDefinition.getGroups()) - { - if (StudyManager.getInstance().getCohortByLabel(getContainer(), getUser(), defGroup.getName()) == null) - return true; - } - return false; - } -} diff --git a/study/src/org/labkey/study/designer/StudyDesignInfo.java b/study/src/org/labkey/study/designer/StudyDesignInfo.java deleted file mode 100644 index b196a87f602..00000000000 --- a/study/src/org/labkey/study/designer/StudyDesignInfo.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2008-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.study.designer; - -import org.labkey.api.data.Container; -import org.labkey.api.exp.Lsid; - -import java.util.Date; - -/** - * User: Mark Igra - * Date: Feb 13, 2007 - * Time: 9:59:12 AM - */ -public class StudyDesignInfo -{ - private int studyId; - private int createdBy; - private Date created; - private int modifiedBy; - private Date modified; - private Container container; - private int publicRevision; - private int draftRevision; - private String label; - private Container sourceContainer; - private boolean active; - - public int getStudyId() - { - return studyId; - } - - public void setStudyId(int studyId) - { - this.studyId = studyId; - } - - public int getCreatedBy() - { - return createdBy; - } - - public void setCreatedBy(int createdBy) - { - this.createdBy = createdBy; - } - - public Date getCreated() - { - return created; - } - - public void setCreated(Date created) - { - this.created = created; - } - - public int getModifiedBy() - { - return modifiedBy; - } - - public void setModifiedBy(int modifiedBy) - { - this.modifiedBy = modifiedBy; - } - - public Date getModified() - { - return modified; - } - - public void setModified(Date modified) - { - this.modified = modified; - } - - public Container getContainer() - { - return container; - } - - public void setContainer(Container container) - { - this.container = container; - if (null == sourceContainer) - this.sourceContainer = container; - } - - public int getPublicRevision() - { - return publicRevision; - } - - public void setPublicRevision(int publicRevision) - { - this.publicRevision = publicRevision; - } - - public int getDraftRevision() - { - return draftRevision; - } - - public void setDraftRevision(int draftRevision) - { - this.draftRevision = draftRevision; - } - - public String getLabel() - { - return label; - } - - public void setLabel(String label) - { - this.label = label; - } - - public Lsid getLsid() - { - return new Lsid("study-design", String.valueOf(getStudyId())); - } - - public Container getSourceContainer() { - return sourceContainer; - } - - public void setSourceContainer(Container sourceContainer) { - this.sourceContainer = sourceContainer; - } - - public boolean isActive() - { - return active; - } - - public void setActive(boolean active) - { - this.active = active; - } -} diff --git a/study/src/org/labkey/study/designer/StudyDesignManager.java b/study/src/org/labkey/study/designer/StudyDesignManager.java index df284640d4e..58cf47ebdfd 100644 --- a/study/src/org/labkey/study/designer/StudyDesignManager.java +++ b/study/src/org/labkey/study/designer/StudyDesignManager.java @@ -16,57 +16,22 @@ package org.labkey.study.designer; -import gwt.client.org.labkey.study.designer.client.model.GWTAssayDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTAssayNote; -import gwt.client.org.labkey.study.designer.client.model.GWTAssaySchedule; -import gwt.client.org.labkey.study.designer.client.model.GWTCohort; -import gwt.client.org.labkey.study.designer.client.model.GWTSampleMeasure; -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTTimepoint; -import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.Logger; import org.labkey.api.data.Container; -import org.labkey.api.data.ContainerFilter; -import org.labkey.api.data.ContainerManager; import org.labkey.api.data.DbSchema; import org.labkey.api.data.DbScope; import org.labkey.api.data.Filter; import org.labkey.api.data.SQLFragment; import org.labkey.api.data.SimpleFilter; -import org.labkey.api.data.Sort; import org.labkey.api.data.SqlExecutor; import org.labkey.api.data.SqlSelector; import org.labkey.api.data.Table; import org.labkey.api.data.TableInfo; -import org.labkey.api.data.TableSelector; import org.labkey.api.exp.OntologyManager; -import org.labkey.api.exp.PropertyType; import org.labkey.api.exp.property.Domain; import org.labkey.api.exp.property.PropertyService; -import org.labkey.api.module.FolderTypeManager; -import org.labkey.api.query.FieldKey; -import org.labkey.api.query.ValidationException; -import org.labkey.api.security.SecurityManager; import org.labkey.api.security.User; -import org.labkey.api.specimen.SpecimenMigrationService; -import org.labkey.api.study.Dataset; -import org.labkey.api.study.Study; -import org.labkey.api.study.TimepointType; -import org.labkey.api.study.Visit; -import org.labkey.api.study.publish.StudyPublishService; -import org.labkey.api.util.Pair; -import org.labkey.api.view.HttpView; -import org.labkey.api.view.Portal; -import org.labkey.study.StudyFolderType; -import org.labkey.study.StudyModule; import org.labkey.study.StudySchema; -import org.labkey.study.assay.StudyPublishManager; -import org.labkey.study.controllers.designer.DesignerController; -import org.labkey.study.model.CohortImpl; -import org.labkey.study.model.DatasetDefinition; -import org.labkey.study.model.StudyImpl; -import org.labkey.study.model.StudyManager; -import org.labkey.study.model.VisitImpl; import org.labkey.study.query.StudyPersonnelDomainKind; import org.labkey.study.query.StudyQuerySchema; import org.labkey.study.query.studydesign.AbstractStudyDesignDomainKind; @@ -75,17 +40,7 @@ import org.labkey.study.query.studydesign.StudyTreatmentDomainKind; import org.labkey.study.query.studydesign.StudyTreatmentProductDomainKind; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; import static org.labkey.study.query.StudyQuerySchema.PERSONNEL_TABLE_NAME; @@ -94,16 +49,8 @@ import static org.labkey.study.query.StudyQuerySchema.TREATMENT_PRODUCT_MAP_TABLE_NAME; import static org.labkey.study.query.StudyQuerySchema.TREATMENT_TABLE_NAME; -/** - * User: Mark Igra - * Date: Feb 12, 2007 - * Time: 5:06:04 PM - - */ public class StudyDesignManager { - private static final String STUDY_DESIGN_TABLE_NAME = "StudyDesign"; - private static final String STUDY_VERSION_TABLE_NAME = "StudyDesignVersion"; private static final StudyDesignManager _instance = new StudyDesignManager(); public static StudyDesignManager get() @@ -116,229 +63,6 @@ public DbSchema getSchema() return StudySchema.getInstance().getSchema(); } - public TableInfo getStudyDesignTable() - { - return getSchema().getTable(STUDY_DESIGN_TABLE_NAME); - } - - public TableInfo getStudyVersionTable() - { - return getSchema().getTable(STUDY_VERSION_TABLE_NAME); - } - - public StudyDesignInfo getStudyDesign(Container c, int studyId) - { - SimpleFilter filter = new SimpleFilter(); - filter.addWhereClause("(Container = ? OR SourceContainer = ?) AND StudyId= ?", new Object[] {c.getId(), c.getId(), studyId} , FieldKey.fromParts("Container"), FieldKey.fromParts("SourceContainer"), FieldKey.fromParts("StudyId")); - - return new TableSelector(getStudyDesignTable(), filter, null).getObject(StudyDesignInfo.class); - } - - public StudyDesignInfo[] getStudyDesigns(Container c) - { - SimpleFilter filter = new SimpleFilter(); - filter.addWhereClause("(Container = ? OR SourceContainer = ?)", new Object[] {c, c} , FieldKey.fromParts("Container"), FieldKey.fromParts("SourceContainer")); - - return new TableSelector(getStudyDesignTable(), filter, null).getArray(StudyDesignInfo.class); - } - - public StudyDesignInfo[] getStudyDesignsForAllFolders(User u, Container root) - { - SimpleFilter filter = new SimpleFilter(); - ContainerFilter cf = ContainerFilter.Type.CurrentAndSubfolders.create(root, u); - filter.addClause(cf.createFilterClause(getSchema(), FieldKey.fromParts("Container"))); - - return new TableSelector(getStudyDesignTable(), filter, null).getArray(StudyDesignInfo.class); - } - - - public StudyDesignInfo moveStudyDesign(User user, StudyDesignInfo design, Container newContainer) - { - Container oldContainer = design.getContainer(); - design.setContainer(newContainer); - Table.update(user, getStudyDesignTable(), design, design.getStudyId()); - String sql = "UPDATE " + getStudyVersionTable() + " SET Container = ? WHERE Container = ? AND StudyId = ?"; - new SqlExecutor(getSchema()).execute(sql, newContainer, oldContainer, design.getStudyId()); - - return design; - } - - /** - * Copies a study design. The new design will have a revisionid of 1 and will only copy the latest revision - * @param user - * @param source StudyDesign to copy - * @param newContainer May be same as old container if name is different - * @param newName Label for this study design - * @return - */ - public StudyDesignInfo copyStudyDesign(User user, StudyDesignInfo source, Container newContainer, String newName) throws SaveException - { - StudyDesignInfo dest = new StudyDesignInfo(); - dest.setLabel(newName); - dest.setContainer(newContainer); - dest.setStudyId(0); - dest.setDraftRevision(0); - dest.setPublicRevision(1); - dest = insertStudyDesign(user, dest); - - StudyDesignVersion version = getStudyDesignVersion(source.getContainer(), source.getStudyId()); - version.setStudyId(dest.getStudyId()); - version.setLabel(newName); - version.setRevision(0); - version.setContainer(newContainer); - saveStudyDesign(user, newContainer, version); - - return dest; - } - - public StudyDesignInfo getStudyDesign(Container c, String name) - { - return getStudyDesign(c, name, false); - } - - public StudyDesignInfo getStudyDesign(Container c, String name, boolean checkSourceContainer) - { - SimpleFilter filter = SimpleFilter.createContainerFilter(c); - filter.addCondition(FieldKey.fromParts("Label"), name); - StudyDesignInfo[] designs = new TableSelector(getStudyDesignTable(), filter, null).getArray(StudyDesignInfo.class); - if (designs.length > 0) - return designs[0]; - - // Issue 18393: if the study design has been used to create a study folder, also check the sourcecontainer field - if (checkSourceContainer) - { - filter = new SimpleFilter(FieldKey.fromParts("SourceContainer"), c); - filter.addCondition(FieldKey.fromParts("Label"), name); - designs = new TableSelector(getStudyDesignTable(), filter, null).getArray(StudyDesignInfo.class); - if (designs.length > 0) - return designs[0]; - } - - return null; - } - - public GWTStudyDefinition getGWTStudyDefinition(User user, Container c, StudyDesignInfo info) - { - StudyDesignVersion version = getStudyDesignVersion(info.getContainer(), info.getStudyId()); - - GWTStudyDefinition def = XMLSerializer.fromXML(version.getXML(), user, info.getContainer()); - mergeStudyProperties(def, info); - def.setCavdStudyId(info.getStudyId()); - - return def; - } - - public GWTStudyDefinition mergeStudyProperties(GWTStudyDefinition def, StudyDesignInfo info) - { - if (!info.isActive()) - return def; - - Study study = StudyManager.getInstance().getStudy(info.getContainer()); - if (null != study.getDescription()) - def.setDescription(study.getDescription()); - if (null != study.getInvestigator()) - def.setInvestigator(study.getInvestigator()); - if (null != study.getGrant()) - def.setGrant(study.getGrant()); - - return def; - } - - public StudyDesignInfo insertStudyDesign(User user, StudyDesignInfo info) - { - return Table.insert(user, getStudyDesignTable(), info); - } - - public StudyDesignVersion[] getStudyDesignVersions(Container c, int studyId) - { - SimpleFilter filter = SimpleFilter.createContainerFilter(c); - filter.addCondition(FieldKey.fromParts("studyId"), studyId); - - return new TableSelector(getStudyVersionTable(), filter, new Sort("Revision")).getArray(StudyDesignVersion.class); - } - - public StudyDesignVersion getStudyDesignVersion(Container c, int studyId, int versionId) - { - SimpleFilter filter = SimpleFilter.createContainerFilter(c); - filter.addCondition(FieldKey.fromParts("studyId"), studyId); - filter.addCondition(FieldKey.fromParts("revision"), versionId); - - return new TableSelector(getStudyVersionTable(), filter, null).getObject(StudyDesignVersion.class); - } - - /** - * Return the latest version of the given study. - */ - public StudyDesignVersion getStudyDesignVersion(Container c, int studyId) - { - SimpleFilter filter = SimpleFilter.createContainerFilter(c); - filter.addCondition(FieldKey.fromParts("studyId"), studyId); - filter.addWhereClause("revision = (SELECT MAX(revision) FROM " + getStudyVersionTable().toString() + " WHERE studyid=?)", new Object[] {studyId}, FieldKey.fromParts("revision"), FieldKey.fromParts("studyid")); - - return new TableSelector(getStudyVersionTable(), filter, null).getObject(StudyDesignVersion.class); - } - - /** - * returns null if no revision can be found for the particular study and container - */ - public Integer getLatestRevisionNumber(Container c, int studyId) - { - String sql = "SELECT MAX(Revision) FROM " + getStudyVersionTable().toString() + " WHERE Container = ? AND StudyId = ?"; - return new SqlSelector(getSchema(), sql, c, studyId).getObject(Integer.class); - } - - public StudyDesignVersion saveStudyDesign(User user, Container container, StudyDesignVersion version) throws SaveException - { - int studyDesignId = version.getStudyId(); - StudyDesignInfo designInfo; - - // Check if there is a name conflict - StudyDesignInfo existingStudyDesign = getStudyDesign(container, version.getLabel(), true); - if (existingStudyDesign != null && (0 == studyDesignId || existingStudyDesign.getStudyId() != studyDesignId)) - { - throw new SaveException("The name '" + version.getLabel() + "' is already in use"); - } - - try (DbScope.Transaction transaction = getSchema().getScope().ensureTransaction()) - { - if (0 == studyDesignId) - { - designInfo = new StudyDesignInfo(); - designInfo.setLabel(version.getLabel()); - designInfo.setContainer(container); - designInfo = insertStudyDesign(user, designInfo); - version.setStudyId(designInfo.getStudyId()); - } - else - designInfo = getStudyDesign(container, studyDesignId); - - int revision = designInfo.getPublicRevision() + 1; - version.setRevision(revision); - version.setContainer(designInfo.getContainer()); - - version = Table.insert(user, getStudyVersionTable(), version); - designInfo.setPublicRevision(version.getRevision()); - designInfo.setLabel(version.getLabel()); - Table.update(user, getStudyDesignTable(), designInfo, designInfo.getStudyId()); - transaction.commit(); - } - - return version; - } - - public void deleteStudyDesigns(Container c, Set deletedTables) - { - inactivateStudyDesign(c); - Filter filter = SimpleFilter.createContainerFilter(c); - Table.delete(getStudyVersionTable(), filter); - deletedTables.add(getStudyVersionTable()); - Table.delete(getStudyDesignTable(), filter); - deletedTables.add(getStudyDesignTable()); - //Legacy design sourceContainer "remembered" where the study design was created. If deleting sourceContainer make sure don't have orphan rows - SQLFragment updateContainers = new SQLFragment("UPDATE " + getStudyDesignTable() + " SET sourceContainer=container WHERE sourceContainer=?", c); - new SqlExecutor(getSchema()).execute(updateContainers); - } - public void deleteStudyDesignLookupValues(Container c, Set deletedTables) { Filter filter = SimpleFilter.createContainerFilter(c); @@ -364,329 +88,6 @@ public void deleteStudyDesignLookupValues(Container c, Set deletedTab deletedTables.add(StudySchema.getInstance().getTableInfoDoseAndRoute()); } - public void inactivateStudyDesign(Container c) - { - //If designs were sourced from another folder. Just move ownership back so new studies can be created - Study study = StudyManager.getInstance().getStudy(c); - if (null != study) - { - StudyDesignInfo studyDesign = getDesignForStudy(StudyManager.getInstance().getStudy(c)); - if (null != studyDesign) - { - //First mark as inactive - studyDesign.setActive(false); - Table.update(HttpView.currentContext().getUser(), getStudyDesignTable(), studyDesign, studyDesign.getStudyId()); - if (!c.equals(studyDesign.getSourceContainer())) - moveStudyDesign(HttpView.currentContext().getUser(), studyDesign, studyDesign.getSourceContainer()); - } - } - } - - public void deleteStudyDesign(Container container, int studyId) - { - SimpleFilter deleteVersionsFilter = SimpleFilter.createContainerFilter(container); - deleteVersionsFilter.addCondition(FieldKey.fromParts("studyId"), studyId); - Table.delete(getStudyVersionTable(), deleteVersionsFilter); - - SimpleFilter deleteDesignInfoFilter = SimpleFilter.createContainerFilter(container); - deleteDesignInfoFilter.addCondition(FieldKey.fromParts("studyId"), studyId); - Table.delete(getStudyDesignTable(), deleteDesignInfoFilter); - } - - public Study generateStudyFromDesign(User user, Container parent, String folderName, Date startDate, - String subjectNounSingular, String subjectNounPlural, String subjectColumnName, StudyDesignInfo info, - List> participantDataset, List> specimens) throws IOException, ValidationException - { - Container studyFolder = parent.getChild(folderName); - if (null == studyFolder) - studyFolder = ContainerManager.createContainer(parent, folderName, user); - if (null != StudyManager.getInstance().getStudy(studyFolder)) - throw new IllegalStateException("Study already exists in folder"); - - SecurityManager.setInheritPermissions(studyFolder); - studyFolder.setFolderType(FolderTypeManager.get().getFolderType(StudyFolderType.NAME), user); - - //Grab study info from XML and use it here - StudyDesignVersion version = StudyDesignManager.get().getStudyDesignVersion(info.getContainer(), info.getStudyId()); - GWTStudyDefinition def = XMLSerializer.fromXML(version.getXML(), user, studyFolder); - - StudyImpl study = new StudyImpl(studyFolder, folderName + " Study"); - study.setTimepointType(TimepointType.DATE); - study.setStartDate(startDate); - study.setSubjectNounSingular(subjectNounSingular); - study.setSubjectNounPlural(subjectNounPlural); - study.setSubjectColumnName(subjectColumnName); - study.setDescription(def.getDescription()); - study.setGrant(def.getGrant()); - study.setInvestigator(def.getInvestigator()); - study = StudyManager.getInstance().createStudy(user, study); - - List timepoints = def.getAssaySchedule().getTimepoints(); - Collections.sort(timepoints); - if (timepoints.get(0).getDays() > 0) - timepoints.add(0, new GWTTimepoint("Study Start", 0, GWTTimepoint.DAYS)); - - //We try to create timepoints that make sense. A week is day-3 to day +3 unless that would overlap - double previousDay = timepoints.get(0).getDays() - 1.0; - for (int timepointIndex = 0; timepointIndex < timepoints.size(); timepointIndex++) - { - GWTTimepoint timepoint = timepoints.get(timepointIndex); - double startDay = timepoints.get(timepointIndex).getDays(); - double endDay = startDay; - double nextDay = timepointIndex + 1 == timepoints.size() ? Double.MAX_VALUE : timepoints.get(timepointIndex + 1).getDays(); - if (timepoint.getUnit() == GWTTimepoint.WEEKS) - { - startDay = Math.max(previousDay + 1, startDay - 3); - endDay = Math.min(nextDay - 1, endDay + 3); - } - else if (timepoint.getUnit() == GWTTimepoint.MONTHS) - { - startDay = Math.max(previousDay + 1, startDay - 15); - endDay = Math.min(nextDay - 1, endDay + 15); - } - VisitImpl visit = new VisitImpl(studyFolder, BigDecimal.valueOf(startDay), BigDecimal.valueOf(endDay), timepoint.toString(), Visit.Type.REQUIRED_BY_TERMINATION); - StudyManager.getInstance().createVisit(study, user, visit); - previousDay = endDay; - } - - Map nameMap = new HashMap<>(); - //TODO: Not quite right. Really should use types culled from tabloader - for (String propertyId : participantDataset.get(0).keySet()) - { - Object val = participantDataset.get(0).get(propertyId); - nameMap.put(propertyId, null == val ? PropertyType.STRING : PropertyType.getFromClass(val.getClass())); - } - List errors = new ArrayList<>(); - - Dataset subjectDataset = StudyPublishManager.getInstance().createDataset(user, new DatasetDefinition.Builder("Subjects") - .setStudy(study) - .setDemographicData(true)); - - study = study.createMutable(); - study.setParticipantCohortDatasetId(subjectDataset.getDatasetId()); - study.setParticipantCohortProperty("Cohort"); - StudyManager.getInstance().updateStudy(user, study); - - StudyPublishService.get().publishData(user, parent, studyFolder, "Subjects", Pair.of(Dataset.PublishSource.Assay, null), participantDataset, nameMap, errors); - if (errors.size() > 0) //We were supposed to check these coming in - throw new RuntimeException(StringUtils.join(errors, '\n')); - - //Need to make the dataset at least optional for some visit -// DatasetDefinition[] dsds = StudyManager.getInstance().getDatasetDefinitions(study); -// for (DatasetDefinition dsd : dsds) -// StudyManager.getInstance().updateVisitDatasetMapping(user, study.getContainer(), 1, dsd.getDatasetId(), VisitDatasetType.OPTIONAL); - - SpecimenMigrationService sms = SpecimenMigrationService.get(); - if (null != sms) - sms.importSpecimens(study.getContainer(), user, specimens); - - //Move study design into study folder... - moveStudyDesign(user, info, study.getContainer()); - info.setActive(true); - //and attach to this study - Table.update(user, getStudyDesignTable(), info, info.getStudyId()); - - Portal.addPart(study.getContainer(), StudyModule.studyDesignSummaryWebPartFactory, null, 0); - - return study; - } - - public List> generateParticipantDataset(User user, GWTStudyDefinition def) - { - List cohorts = def.getGroups(); - int count = 0; - for (GWTCohort cohort : cohorts) - count += cohort.getCount(); - - List> participantInfo = new ArrayList<>(count); - for (int cohortNum = 0; cohortNum < cohorts.size(); cohortNum++) - { - GWTCohort cohort = cohorts.get(cohortNum); - String participantId; - - for (int participantNum = 0; participantNum < cohort.getCount(); participantNum++) - { - participantId = sprintf("%03d%02d%02d", def.getCavdStudyId(), cohortNum + 1, participantNum + 1); - Map m = new HashMap<>(); - m.put("ParticipantId", participantId); - m.put("Cohort", cohort.getName()); - m.put("Index", participantNum + 1); - m.put("SequenceNum", 1.0); - participantInfo.add(m); - } - } - return participantInfo; - } - - /** - * Generate a list of samples that can be uploaded. Rule is - * For each timepoint - * For each cohort - * For each individual - * Produce 1 vial - * Numbering: Sample is StudyId+TimePointIndex+CohortIndex+IndividualIndex+S|P|C - * Vial: Sample+N where n is index for that timepoint - * We generate ids for each assay at each timepoint even if assay is not required at that timepoint - * @param studyDefinition - * @param participantInfo - * @return - */ - public List> generateSampleList(GWTStudyDefinition studyDefinition, List> participantInfo, Date studyStartDate) - { - GWTAssaySchedule assaySchedule = studyDefinition.getAssaySchedule(); - List timepoints = assaySchedule.getTimepoints(); - Collections.sort(timepoints); - Map> vialsPerSampleType = new HashMap<>(); - for (GWTAssayDefinition def : assaySchedule.getAssays()) - { - for (GWTTimepoint tp : timepoints) - { - Map timepointSamples = vialsPerSampleType.get(tp); - if (null == timepointSamples) - { - timepointSamples = new HashMap<>(); - vialsPerSampleType.put(tp, timepointSamples); - } - GWTAssayNote note = assaySchedule.getAssayPerformed(def, tp); - GWTSampleMeasure measure; - if (null != note) - { - measure = note.getSampleMeasure(); - timepointSamples.put(measure.getType(), 1); - } - } - } - - //CONSIDER: Use something like ArrayListMap to share hash table space - List> rows = new ArrayList<>(); - int timepointIndex = 1; //Use one based - for (GWTTimepoint tp : timepoints) - { - Map timepointSamples = vialsPerSampleType.get(tp); - for (Map participant : participantInfo) - { - Date startDate = (Date) participant.get("StartDate"); - if (startDate == null) - startDate = studyStartDate; - - String ptid = participant.get("ParticipantId").toString(); - for (String st : timepointSamples.keySet()) - { - String sampleId = ptid + "-" + tp.getDays(); - Map m = new HashMap<>(); - m.put(SpecimenMigrationService.VISIT, timepointIndex); - m.put(SpecimenMigrationService.PARTICIPANT_ID, ptid); - m.put(SpecimenMigrationService.SAMPLE_ID, sampleId); - m.put(SpecimenMigrationService.VIAL_ID, sampleId + (timepointSamples.size() == 1 ? "" : st)); - m.put(SpecimenMigrationService.DERIVATIVE_TYPE, st); - m.put(SpecimenMigrationService.DRAW_TIMESTAMP, getDay(startDate, tp.getDays())); - rows.add(m); - } - } - timepointIndex++; - } - return rows; - } - - private Date getDay(Date startDate, int days) - { - Calendar c = Calendar.getInstance(); - c.setTime(startDate); - c.add(Calendar.DAY_OF_MONTH, days); - return c.getTime(); - } - - private static String sprintf(String pat, Object... args) - { - StringWriter s = new StringWriter(); - PrintWriter pw = new PrintWriter(s); - //TODO: Checksum - pw.printf(pat, args); - return s.toString(); - } - - public StudyDesignInfo getDesignForStudy(Study study) - { - SimpleFilter filter = SimpleFilter.createContainerFilter(study.getContainer()); - filter.addCondition(FieldKey.fromParts("Active"), Boolean.TRUE); - StudyDesignInfo info = new TableSelector(getStudyDesignTable(), filter, null).getObject(StudyDesignInfo.class); - return info; - } - - - public StudyDesignInfo ensureDesignForStudy(User user, Study study, boolean createIfNull) throws Exception - { - StudyDesignInfo info = getDesignForStudy(study); - if (null == info && createIfNull) - { - info = createDesignForStudy(user, study); - } - - return info; - } - - private StudyDesignInfo createDesignForStudy(User user, Study study) throws Exception - { - GWTStudyDefinition def = DesignerController.getTemplate(user, study.getContainer()); - def.setStudyName(study.getLabel()); - StudyDesignVersion version = new StudyDesignVersion(); - version.setContainer(study.getContainer()); - version.setDescription(study.getDescription()); - version.setLabel(study.getLabel()); - version.setXML(XMLSerializer.toXML(def).toString()); - version = saveStudyDesign(user, study.getContainer(), version); - StudyDesignInfo info = getStudyDesign(study.getContainer(), version.getStudyId()); - info.setLabel(study.getLabel()); - info.setActive(true); - Table.update(user, getStudyDesignTable(), info, info.getStudyId()); - - return info; - } - - public List getStudyDesignLookupValues(User user, Container c, TableInfo studyDesignTable) - { - return getStudyDesignLookupValues(user, c, studyDesignTable, true, true); - } - - public List getStudyDesignLookupValues(User user, Container c, TableInfo studyDesignTable, boolean includeProject, boolean excludeInactive) - { - if (c != null && studyDesignTable != null) - { - SimpleFilter filter = new SimpleFilter(); - if (includeProject) - { - ContainerFilter containerFilter = ContainerFilter.Type.CurrentPlusProject.create(c, user); - filter.addCondition(containerFilter.createFilterClause(getSchema(), FieldKey.fromParts("Container"))); - } - else - filter = SimpleFilter.createContainerFilter(c); - - if (excludeInactive) - filter.addCondition(FieldKey.fromParts("Inactive"), false); - - return new TableSelector(studyDesignTable, Collections.singleton("Name"), filter, new Sort("Name")).getArrayList(String.class); - } - else - return Collections.emptyList(); - } - - public List getStudyCohorts(User user, Container c) - { - StudyImpl study = StudyManager.getInstance().getStudy(c); - if (study != null) - { - List cohortNames = new ArrayList<>(); - for (CohortImpl cohort : study.getCohorts(user)) - cohortNames.add(cohort.getLabel()); - - return cohortNames; - } - else - { - return Collections.emptyList(); - } - } - // Proactively create the domains at study creation time to avoid problems with lazy creation, #42641 public void ensureStudyDesignDomains(Container c, User user) { diff --git a/study/src/org/labkey/study/designer/StudyDesignVersion.java b/study/src/org/labkey/study/designer/StudyDesignVersion.java deleted file mode 100644 index 00a5a68fac6..00000000000 --- a/study/src/org/labkey/study/designer/StudyDesignVersion.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2008-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.study.designer; - -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDesignVersion; -import org.labkey.api.data.Container; -import org.labkey.api.security.User; -import org.labkey.api.security.UserManager; -import org.labkey.api.view.ViewContext; - -import java.util.Date; - -/** - * User: Mark Igra - * Date: Feb 12, 2007 - * Time: 10:44:20 AM - */ -public class StudyDesignVersion -{ - private int studyId; - private int createdBy; - private Date created; - private Container container; - private int revision; - private boolean draft; - private String label; - private String description; - private String XML; - - public int getStudyId() - { - return studyId; - } - - public void setStudyId(int studyId) - { - this.studyId = studyId; - } - - public int getCreatedBy() - { - return createdBy; - } - - public void setCreatedBy(int createdBy) - { - this.createdBy = createdBy; - } - - public Date getCreated() - { - return created; - } - - public void setCreated(Date created) - { - this.created = created; - } - - public Container getContainer() - { - return container; - } - - public void setContainer(Container container) - { - this.container = container; - } - - public int getRevision() - { - return revision; - } - - public void setRevision(int revision) - { - this.revision = revision; - } - - public boolean isDraft() - { - return draft; - } - - public void setDraft(boolean draft) - { - this.draft = draft; - } - - public String getLabel() - { - return label; - } - - public void setLabel(String label) - { - this.label = label; - } - - public String getDescription() - { - return description; - } - - public void setDescription(String description) - { - this.description = description; - } - - public String getXML() - { - return XML; - } - - public void setXML(String XML) - { - this.XML = XML; - } - - public GWTStudyDesignVersion toGWTVersion(ViewContext context) - { - GWTStudyDesignVersion gwtVersion = new GWTStudyDesignVersion(); - gwtVersion.setLabel(getLabel()); - User user = UserManager.getUser(getCreatedBy()); - if (null != user) - gwtVersion.setWriterName(user.getDisplayName(context.getUser())); - - gwtVersion.setCreated(new Date(getCreated().getTime())); - gwtVersion.setStudyId(getStudyId()); - gwtVersion.setRevision(getRevision()); - gwtVersion.setSaveSuccessful(true); - - return gwtVersion; - } -} diff --git a/study/src/org/labkey/study/designer/XMLSerializer.java b/study/src/org/labkey/study/designer/XMLSerializer.java deleted file mode 100644 index 3e6e74882cb..00000000000 --- a/study/src/org/labkey/study/designer/XMLSerializer.java +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (c) 2008-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.study.designer; - -import gwt.client.org.labkey.study.designer.client.model.GWTAdjuvant; -import gwt.client.org.labkey.study.designer.client.model.GWTAntigen; -import gwt.client.org.labkey.study.designer.client.model.GWTAssayDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTAssayNote; -import gwt.client.org.labkey.study.designer.client.model.GWTAssaySchedule; -import gwt.client.org.labkey.study.designer.client.model.GWTCohort; -import gwt.client.org.labkey.study.designer.client.model.GWTImmunization; -import gwt.client.org.labkey.study.designer.client.model.GWTImmunizationSchedule; -import gwt.client.org.labkey.study.designer.client.model.GWTImmunogen; -import gwt.client.org.labkey.study.designer.client.model.GWTSampleMeasure; -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition; -import gwt.client.org.labkey.study.designer.client.model.GWTTimepoint; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.xmlbeans.XmlError; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlOptions; -import org.labkey.api.data.Container; -import org.labkey.api.security.User; -import org.labkey.study.StudySchema; -import org.labkey.study.model.CohortImpl; -import org.labkey.study.model.StudyManager; -import org.labkey.study.xml.Adjuvant; -import org.labkey.study.xml.AdjuvantRef; -import org.labkey.study.xml.Antigen; -import org.labkey.study.xml.AssayEvent; -import org.labkey.study.xml.AssayRef; -import org.labkey.study.xml.AssaySchedule; -import org.labkey.study.xml.Cohort; -import org.labkey.study.xml.Immunization; -import org.labkey.study.xml.ImmunizationEvent; -import org.labkey.study.xml.ImmunizationSchedule; -import org.labkey.study.xml.Immunogen; -import org.labkey.study.xml.ImmunogenRef; -import org.labkey.study.xml.SampleMeasure; -import org.labkey.study.xml.StudyDesign; -import org.labkey.study.xml.StudyDesignDocument; -import org.labkey.study.xml.Timepoint; - -import java.util.ArrayList; -import java.util.List; - -/** - * User: Mark Igra - * Date: Feb 14, 2007 - * Time: 10:30:36 PM - */ -public class XMLSerializer -{ - private static Logger _log = LogManager.getLogger(XMLSerializer.class); - - public static GWTStudyDefinition fromXML(String xml, User user, Container c) - { - return fromXML(xml, null, user, c); - } - - public static GWTStudyDefinition fromXML(String xml, GWTStudyDefinition template, User user, Container c) - { - - StudyDesignDocument doc; - try - { - doc = StudyDesignDocument.Factory.parse(xml); - } catch (XmlException e) - { - _log.error(e); - throw new RuntimeException(e); - } - - StudyDesign xdesign = doc.getStudyDesign(); - assert validate(doc); - - GWTStudyDefinition def = new GWTStudyDefinition(); - - // Set the initial lookup values based on the Container/Project study design lookup tables - def.setImmunogenTypes(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignImmunogenTypes())); - def.setGenes(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignGenes())); - def.setRoutes(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignRoutes())); - def.setSubTypes(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignSubTypes())); - def.setSampleTypes(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignSampleTypes())); - def.setUnits(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignUnits())); - def.setAssays(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignAssays())); - def.setLabs(StudyDesignManager.get().getStudyDesignLookupValues(user, c, StudySchema.getInstance().getTableInfoStudyDesignLabs())); - - // Set the cohort choices based on the current study configuration - if (StudyManager.getInstance().showCohorts(c, user)) - def.setCohorts(StudyDesignManager.get().getStudyCohorts(user, c)); - - // set the study top level properties based on the saved info - def.setStudyName(xdesign.getName()); - def.setGrant(xdesign.getGrantName()); - def.setInvestigator(xdesign.getInvestigator()); - def.setAnimalSpecies(xdesign.getAnimalSpecies()); - if (xdesign.isSetDescription()) - def.setDescription(xdesign.getDescription()); - - List immunogens = new ArrayList<>(); - for (Immunogen immunogen : xdesign.getImmunogens().getImmunogenArray()) - { - GWTImmunogen gimmunogen = new GWTImmunogen(immunogen.getName(), immunogen.getDose(), immunogen.getType(), immunogen.getAdmin()); - List antigens = new ArrayList<>(); - for (Antigen antigen : immunogen.getAntigens().getAntigenArray()) - antigens.add(new GWTAntigen(antigen.getName(), antigen.getGene(), antigen.getSubtype(), antigen.getGenBankId(), antigen.getSequence())); - gimmunogen.setAntigens(antigens); - immunogens.add(gimmunogen); - } - def.setImmunogens(immunogens); - - List adjuvants = new ArrayList<>(); - for (Adjuvant adjuvant : xdesign.getAdjuvants().getAdjuvantArray()) - adjuvants.add(new GWTAdjuvant(adjuvant.getName(), adjuvant.getDose(), adjuvant.getAdmin())); - def.setAdjuvants(adjuvants); - - //TODO: XML for cohort descriptions - for (Cohort cohort : xdesign.getCohorts().getCohortArray()) - { - GWTCohort gwtCohort = new GWTCohort(cohort.getName(), null, cohort.getCount(), null); - if (StudyManager.getInstance().showCohorts(c, user)) - { - CohortImpl existingCohort = StudyManager.getInstance().getCohortByLabel(c, user, cohort.getName()); - if (existingCohort != null) - gwtCohort.setCohortId(existingCohort.getRowId()); - } - - def.getGroups().add(gwtCohort); - } - - GWTAssaySchedule gAssaySchedule = new GWTAssaySchedule(); - AssaySchedule xAssaySchedule = xdesign.getAssaySchedule(); - if (null != xAssaySchedule.getDescription()) - gAssaySchedule.setDescription(xAssaySchedule.getDescription()); - - AssaySchedule.Assays assays = xAssaySchedule.getAssays(); - if (null != assays) - { - for (AssayRef ref : assays.getAssayRefArray()) - { - GWTAssayDefinition gad = new GWTAssayDefinition(ref.getAssayName(), ref.getLab()); - gAssaySchedule.getAssays().add(gad); - } - } - - //Note: timepoint storage is somewhat redundant for backward compatibility - //The complete list of timepoints is retrieved here to support empty schdules - //Assay events serialize their entire timepoint descriptor as well - AssaySchedule.Timepoints timepoints = xAssaySchedule.getTimepoints(); - if (null != timepoints) - for (Timepoint tp : timepoints.getTimepointArray()) - { - GWTTimepoint.Unit unit = GWTTimepoint.Unit.fromString(tp.getDisplayUnit()); - GWTTimepoint gtp = new GWTTimepoint(tp.getName(), tp.getDays()/unit.daysPerUnit, unit); - gAssaySchedule.addTimepoint(gtp); - } - - for (AssayEvent evt : xAssaySchedule.getAssayEventArray()) - { - Timepoint tp = evt.getTimepoint(); - GWTTimepoint.Unit unit = GWTTimepoint.Unit.fromString(tp.getDisplayUnit()); - GWTTimepoint gtp = new GWTTimepoint(tp.getName(), tp.getDays()/unit.daysPerUnit, unit); - GWTAssayDefinition gad = findAssayDefinition(evt.getAssayName(), gAssaySchedule.getAssays()); - gAssaySchedule.setAssayPerformed(gad, gtp, new GWTAssayNote(createGWTSampleMeasure(evt.getSampleMeasure()))); - } - def.setAssaySchedule(gAssaySchedule); - - GWTImmunizationSchedule gImmunizationSchedule = new GWTImmunizationSchedule(); - ImmunizationSchedule.Timepoints immunizationTimepoints = xdesign.getImmunizationSchedule().getTimepoints(); - if (null != immunizationTimepoints) - for (Timepoint tp : immunizationTimepoints.getTimepointArray()) - { - GWTTimepoint.Unit unit = GWTTimepoint.Unit.fromString(tp.getDisplayUnit()); - GWTTimepoint gtp = new GWTTimepoint(tp.getName(), tp.getDays()/unit.daysPerUnit, unit); - gImmunizationSchedule.addTimepoint(gtp); - } - - for (ImmunizationEvent evt : xdesign.getImmunizationSchedule().getImmunizationEventArray()) - { - - Timepoint tp = evt.getTimepoint(); - GWTTimepoint.Unit unit = GWTTimepoint.Unit.fromString(tp.getDisplayUnit()); - GWTTimepoint gtp = new GWTTimepoint(tp.getName(), tp.getDays() / unit.daysPerUnit, GWTTimepoint.Unit.fromString(tp.getDisplayUnit())); - GWTImmunization immunization = new GWTImmunization(); - for (ImmunogenRef immunogenRef : evt.getImmunization().getImmunogenRefArray()) - { - GWTImmunogen gImmunogen = findImmunogen(immunogenRef.getName(), def.getImmunogens()); - if (null != gImmunogen) - immunization.immunogens.add(gImmunogen); - } - for (AdjuvantRef adjuvantRef : evt.getImmunization().getAdjuvantRefArray()) - { - GWTAdjuvant gAdjuvant = findAdjuvant(adjuvantRef.getName(), def.getAdjuvants()); - if (null != gAdjuvant) - immunization.adjuvants.add(gAdjuvant); - } - String groupName = evt.getGroupName(); - gImmunizationSchedule.setImmunization(findCohort(groupName, def.getGroups()), gtp, immunization); - } - def.setImmunizationSchedule(gImmunizationSchedule); - - return def; - } - - public static StudyDesignDocument toXML(GWTStudyDefinition def) - { - try - { - StudyDesignDocument doc = StudyDesignDocument.Factory.newInstance(); - StudyDesign x = doc.addNewStudyDesign(); - x.setGrantName(def.getGrant()); - x.setInvestigator(def.getInvestigator()); - x.setName(def.getStudyName()); - x.setAnimalSpecies(def.getAnimalSpecies()); - if (null != def.getDescription()) - x.setDescription(def.getDescription()); - - StudyDesign.Immunogens immunogens = x.addNewImmunogens(); - for (int i = 0; i < def.getImmunogens().size(); i++) - { - GWTImmunogen gImmunogen = def.getImmunogens().get(i); - Immunogen xImmunogen = immunogens.addNewImmunogen(); - xImmunogen.setAdmin(gImmunogen.getAdmin()); - xImmunogen.setName(gImmunogen.getName()); - xImmunogen.setDose(gImmunogen.getDose()); - xImmunogen.setType(gImmunogen.getType()); - Immunogen.Antigens antigens = xImmunogen.addNewAntigens(); - for (Object o : gImmunogen.getAntigens()) - { - GWTAntigen gAntigen = (GWTAntigen) o; - Antigen antigen = antigens.addNewAntigen(); - antigen.setGene(gAntigen.getGene()); - antigen.setName(gAntigen.getName()); - if (null != gAntigen.getSequence()) - antigen.setSequence(gAntigen.getSequence()); - if (null != gAntigen.getGenBankId()) - antigen.setGenBankId(gAntigen.getGenBankId()); - antigen.setSubtype(gAntigen.getSubtype()); - } - } - - StudyDesign.Adjuvants adjuvants = x.addNewAdjuvants(); - for (int i = 0; i < def.getAdjuvants().size(); i++) - { - GWTAdjuvant gAdjuvant = def.getAdjuvants().get(i); - Adjuvant xImmunogen = adjuvants.addNewAdjuvant(); - xImmunogen.setAdmin(gAdjuvant.admin); - xImmunogen.setName(gAdjuvant.getName()); - xImmunogen.setDose(gAdjuvant.getDose()); - } - - - StudyDesign.Cohorts cohorts = x.addNewCohorts(); - for (int i = 0; i < def.getGroups().size(); i++) - { - GWTCohort gwtCohort = def.getGroups().get(i); - Cohort cohort = cohorts.addNewCohort(); - cohort.setName(gwtCohort.getName()); - cohort.setCount(gwtCohort.getCount()); - } - - ImmunizationSchedule xImmunizationSchedule = x.addNewImmunizationSchedule(); - GWTImmunizationSchedule gSchedule = def.getImmunizationSchedule(); - - ImmunizationSchedule.Timepoints timepointsElem = xImmunizationSchedule.addNewTimepoints(); - List immunizationTimepoints = new ArrayList<>(); - for (GWTTimepoint gtp : gSchedule.getTimepoints()) - immunizationTimepoints.add(createTimepoint(gtp)); - timepointsElem.setTimepointArray(immunizationTimepoints.toArray(new Timepoint[immunizationTimepoints.size()])); - - for (GWTCohort gCohort : def.getGroups()) - { - for (GWTTimepoint gtp : gSchedule.getTimepoints()) - { - GWTImmunization gImmunization = gSchedule.getImmunization(gCohort, gtp); - if (null != gImmunization) - { - ImmunizationEvent evt = xImmunizationSchedule.addNewImmunizationEvent(); - Immunization immunization = evt.addNewImmunization(); - for (GWTImmunogen gImmunogen : gImmunization.immunogens) - immunization.addNewImmunogenRef().setName(gImmunogen.getName()); - - for (GWTAdjuvant gAdjuvant : gImmunization.adjuvants) - immunization.addNewAdjuvantRef().setName(gAdjuvant.getName()); - - evt.setGroupName(gCohort.getName()); - evt.setTimepoint(createTimepoint(gtp)); - } - } - } - - AssaySchedule xAssaySchedule = x.addNewAssaySchedule(); - AssaySchedule.Assays assays = xAssaySchedule.addNewAssays(); - AssaySchedule.Timepoints timepoints = xAssaySchedule.addNewTimepoints(); - - GWTAssaySchedule gAssaySchedule = def.getAssaySchedule(); - if (null != gAssaySchedule.getDescription()) - xAssaySchedule.setDescription(gAssaySchedule.getDescription()); - - List scheduleTimepoints = new ArrayList<>(); - for (GWTTimepoint gtp : gAssaySchedule.getTimepoints()) - scheduleTimepoints.add(createTimepoint(gtp)); - timepoints.setTimepointArray(scheduleTimepoints.toArray(new Timepoint[scheduleTimepoints.size()])); - - for (GWTAssayDefinition gwtAssayDefinition : gAssaySchedule.getAssays()) - { - AssayRef assayRef = assays.addNewAssayRef(); - assayRef.setAssayName(gwtAssayDefinition.getAssayName()); - assayRef.setLab(gwtAssayDefinition.getLab()); - - for (GWTTimepoint gwtTimepoint : gAssaySchedule.getTimepoints()) - { - GWTAssayNote gwtAssayNote = gAssaySchedule.getAssayPerformed(gwtAssayDefinition, gwtTimepoint); - if (null != gwtAssayNote) - { - AssayEvent evt = xAssaySchedule.addNewAssayEvent(); - evt.setAssayName(gwtAssayDefinition.getAssayName()); - evt.setTimepoint(createTimepoint(gwtTimepoint)); - evt.setSampleMeasure(createSampleMeasure(gwtAssayNote.getSampleMeasure())); - } - } - } - - assert doc.validate(); - return doc; - } - catch (Exception e) - { - _log.error(e); - throw new RuntimeException(e); - } - } - - - static GWTSampleMeasure createGWTSampleMeasure(SampleMeasure measure) - { - return new GWTSampleMeasure(measure.getAmount(), measure.getUnit(), measure.getType()); - } - - static Timepoint createTimepoint(GWTTimepoint gtp) - { - Timepoint tp = Timepoint.Factory.newInstance(); - tp.setDays(gtp.getDays()); - tp.setDisplayUnit(gtp.getUnit().toString()); - if (null != gtp.getName()) - tp.setName(gtp.getName()); - - return tp; - } - - static SampleMeasure createSampleMeasure(GWTSampleMeasure gwtSampleMeasure) - { - SampleMeasure sm = SampleMeasure.Factory.newInstance(); - if (gwtSampleMeasure != null && !gwtSampleMeasure.isEmpty()) - { - sm.setAmount(gwtSampleMeasure.getAmount()); - if (null != gwtSampleMeasure.getType()) - sm.setType(gwtSampleMeasure.getType()); - if (null != gwtSampleMeasure.getUnit()) - sm.setUnit(gwtSampleMeasure.getUnit()); - } - return sm; - } - - static GWTAssayDefinition findAssayDefinition(String assayName, List assays) - { - for (GWTAssayDefinition def : assays) - if (def.getAssayName().equals(assayName)) - return def; - - return null; - } - - static GWTImmunogen findImmunogen(String name, List immunogens) - { - for (GWTImmunogen i : immunogens) - if (i.getName().equals(name)) - return i; - - return null; - } - - static GWTAdjuvant findAdjuvant(String name, List adjuvants) - { - for (GWTAdjuvant i : adjuvants) - if (i.getName().equals(name)) - return i; - - return null; - } - - static GWTCohort findCohort(String name, List cohorts) - { - for (GWTCohort c : cohorts) - if (c.getName().equals(name)) - return c; - - return null; - } - - static boolean validate(StudyDesignDocument doc) - { - XmlOptions opts = new XmlOptions(); - ArrayList errors = new ArrayList(); - opts.setErrorListener(errors); - boolean valid = doc.validate(opts); - return valid; - } -} - diff --git a/study/src/org/labkey/study/designer/view/StudyDesignsWebPart.java b/study/src/org/labkey/study/designer/view/StudyDesignsWebPart.java deleted file mode 100644 index e64cc62753a..00000000000 --- a/study/src/org/labkey/study/designer/view/StudyDesignsWebPart.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2008-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.labkey.study.designer.view; - -import org.labkey.api.data.ActionButton; -import org.labkey.api.data.ButtonBar; -import org.labkey.api.data.DataColumn; -import org.labkey.api.data.DataRegion; -import org.labkey.api.data.DataRegionSelection; -import org.labkey.api.data.DisplayColumn; -import org.labkey.api.data.RenderContext; -import org.labkey.api.data.SimpleFilter; -import org.labkey.api.data.Sort; -import org.labkey.api.data.TableInfo; -import org.labkey.api.portal.ProjectUrls; -import org.labkey.api.query.DetailsURL; -import org.labkey.api.query.FieldKey; -import org.labkey.api.query.QuerySettings; -import org.labkey.api.security.permissions.AdminPermission; -import org.labkey.api.security.permissions.DeletePermission; -import org.labkey.api.security.permissions.InsertPermission; -import org.labkey.api.security.permissions.UpdatePermission; -import org.labkey.api.util.ContainerContext; -import org.labkey.api.util.PageFlowUtil; -import org.labkey.api.view.ActionURL; -import org.labkey.api.view.GridView; -import org.labkey.api.view.ViewContext; -import org.labkey.study.controllers.designer.DesignerController; -import org.labkey.study.designer.StudyDesignManager; -import org.springframework.validation.BindException; - -import java.io.IOException; -import java.io.Writer; - -/** - * User: Mark Igra - * Date: Feb 15, 2007 - * Time: 4:45:19 PM - */ -public class StudyDesignsWebPart extends GridView -{ - public StudyDesignsWebPart(ViewContext ctx, boolean inPortal) - { - super(new DataRegion(), (BindException)null); - - TableInfo table = StudyDesignManager.get().getStudyDesignTable(); - QuerySettings settings = new QuerySettings(ctx, table.getName()); - settings.setSelectionKey(DataRegionSelection.getSelectionKey(table.getSchema().getName(), table.getName(), null, table.getName())); - - DataRegion dr = getDataRegion(); - dr.setSettings(settings); - dr.addColumns(table.getColumns("StudyId", "Label", "Modified", "PublicRevision","Container", "Active")); - dr.getDisplayColumn("StudyId").setCaption("Id"); - - ActionURL helper = new ActionURL(DesignerController.DesignerAction.class, ctx.getContainer()); - dr.getDisplayColumn("Label").setURL(helper.clone().addParameter("studyId", "${studyId}")); - dr.getDisplayColumn("PublicRevision").setCaption("Revision"); - dr.getDisplayColumn("Container").setVisible(false); - dr.getDisplayColumn("Active").setVisible(false); - DisplayColumn dc = new DataColumn(table.getColumn("Active")) { - - @Override - public void renderGridCellContents(RenderContext ctx, Writer out) throws IOException - { - boolean value = ((Boolean)super.getValue(ctx)).booleanValue(); - if (value) - { - out.write(PageFlowUtil.link("Go To Study Folder").href(renderURL(ctx)).style("white-space:nowrap").toString()); - } - else - { - out.write(" "); - } - } - - @Override - public String getCaption() - { - return ""; - } - }; - final ActionURL studyFolderUrl = PageFlowUtil.urlProvider(ProjectUrls.class).getStartURL(ctx.getContainer()); - DetailsURL url = new DetailsURL(studyFolderUrl); - url.setContainerContext(new ContainerContext.FieldKeyContext(FieldKey.fromParts("Container"))); - dc.setURLExpression(url); - dr.addDisplayColumn(dc); - ButtonBar bb = new ButtonBar(); - if (ctx.getContainer().hasPermission(ctx.getUser(), InsertPermission.class)) - { - helper.addParameter("edit", "true"); - bb.add(new ActionButton("New Protocol", helper)); - } - if (inPortal) - { - if (ctx.getContainer().hasPermission(ctx.getUser(), UpdatePermission.class)) - { - ActionURL adminURL = new ActionURL(DesignerController.BeginAction.class, ctx.getContainer()); - bb.add(new ActionButton("Manage Protocols", adminURL)); - } - } - else - { - if (ctx.getContainer().hasPermission(ctx.getUser(), DeletePermission.class)) - { - dr.setShowRecordSelectors(true); - ActionButton deleteButton = new ActionButton(DesignerController.DeleteAction.class, "Delete"); - deleteButton.setDisplayPermission(DeletePermission.class); - deleteButton.setRequiresSelection(true, "Are you sure you want to delete the selected row?", "Are you sure you want to delete the selected rows?"); - bb.add(deleteButton); - } - else - dr.setShowRecordSelectors(false); - - if (ctx.getContainer().getProject().hasPermission(ctx.getUser(), AdminPermission.class)) - { - ActionURL templateHelper = helper.clone(); - templateHelper.setAction(DesignerController.EditTemplateAction.class); - bb.add(new ActionButton("Edit Template for Project", templateHelper)); - } - } - - dr.setButtonBar(bb); - setTitle("Vaccine Study Protocols"); - setSort(new Sort("Label")); - getRenderContext().setUseContainerFilter(false); - setFilter(new SimpleFilter(FieldKey.fromParts("SourceContainer"), ctx.getContainer())); - } -} diff --git a/study/src/org/labkey/study/designer/view/createRepositoryWizard.jsp b/study/src/org/labkey/study/designer/view/createRepositoryWizard.jsp deleted file mode 100644 index 55da9168baa..00000000000 --- a/study/src/org/labkey/study/designer/view/createRepositoryWizard.jsp +++ /dev/null @@ -1,277 +0,0 @@ -<% -/* - * Copyright (c) 2008-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -%> -<%@ page import="gwt.client.org.labkey.study.designer.client.model.GWTCohort" %> -<%@ page import="org.labkey.api.data.Container" %> -<%@ page import="org.labkey.api.data.ContainerManager" %> -<%@ page import="org.labkey.api.security.User" %> -<%@ page import="org.labkey.api.security.permissions.AdminPermission" %> -<%@ page import="org.labkey.api.util.DateUtil" %> -<%@ page import="org.labkey.api.view.ActionURL" %> -<%@ page import="org.labkey.api.view.HttpView" %> -<%@ page import="org.labkey.study.controllers.designer.DesignerController" %> -<%@ page import="org.labkey.study.controllers.designer.DesignerController.CancelWizardAction" %> -<%@ page import="org.labkey.study.controllers.designer.DesignerController.CreateRepositoryAction" %> -<%@ page import="org.labkey.study.controllers.designer.DesignerController.CreateRepositoryForm" %> -<%@ page import="org.labkey.study.controllers.designer.DesignerController.WizardStep" %> -<%@ page import="java.util.Comparator" %> -<%@ page import="java.util.List" %> -<%@ page import="java.util.Set" %> -<%@ page import="java.util.SortedSet" %> -<%@ page import="java.util.TreeSet" %> -<%@ taglib prefix="labkey" uri="http://www.labkey.org/taglib" %> -<%@ page extends="org.labkey.api.jsp.JspBase" %> -<% - CreateRepositoryForm form = (CreateRepositoryForm) HttpView.currentModel(); - Container container = getContainer(); - User user = getUser(); - String species = DesignerController.getStudyDefinition(form, user, container).getAnimalSpecies(); - ActionURL cancelUrl = urlFor(CancelWizardAction.class).addParameter("studyId", String.valueOf(form.getStudyId())); - if (null != form.getMessage()) - {%> - <%=h(form.getMessage(), true)%>
<% - }%> -Use this wizard to create a folder that will contain the assay results and information about each <%=h(species)%> (subject) within -the vaccine study. - - - - - -<% - if (form.getWizardStep() == WizardStep.PICK_FOLDER) - { -%> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Study Settings
Study Begin Date
Subject Noun (Singular)
Subject Noun (Plural)
Subject Column Name
Study Folder Location
Folder Name
Parent Folder - -
- <%=generateBackButton()%> - <%= button("Next").submit(true) %>  <%= button("Cancel").href(cancelUrl) %> - -<% -} -else -{ -%> - - - - - - -<% -} -if (form.getWizardStep() == WizardStep.SHOW_SAMPLES) -{ -%> -Each study needs specimen ids for the specimens included in the study. To upload the - specimens, follow the instructions below.
-
    -
  1. Download the specimen spreadsheet - <%=link("Download Excel Workbook").href("#downloadSpecimens").onClick("sendFormTo('study-designer-getSpecimenExcel.view')")%>
    -
  2. -
  3. Save the spreadsheet to your computer
  4. -
  5. Fill in the specimen spreadsheet. The following columns must be filled in -
      -
    • Subject -- Unique identifier for the <%=h(species)%>
    • -
    • Day -- The day number when the sample was drawn
    • -
    -
  6. -
  7. Paste data copied from the downloaded workbook and paste in the box below.
  8. -
-
- - -
- <%= generateBackButton() %> - <% if (form.isContainsWarnings()) {%> - <%= button("Ignore Warnings and Continue").submit(true).onClick("form.ignoreWarnings.value = 'true';form.submit();") %> - <%}%> - <%= button("Next").submit(true) %>  <%= button("Cancel").href(cancelUrl) %> -
<% -%> -
-<% -} -if (form.getWizardStep() == WizardStep.UPLOAD_SAMPLES) -{ -%> -Paste a tab-delimited dataset copied from the workbook downloaded in the previous set. Copy the area - containing specimen information and paste it here.
- - -
-<%= generateBackButton() %> - <% if (form.isContainsWarnings()) {%> - <%= button("Ignore Warnings and Continue").submit(true).onClick("form.ignoreWarnings.value = 'true';form.submit();")%> - <%}%> - <%= button("Next").submit(true) %>  <%= button("Cancel").href(cancelUrl) %> -<% -} -if (form.getWizardStep() != WizardStep.UPLOAD_SAMPLES && - form.getWizardStep() != WizardStep.SHOW_SAMPLES) -{ -%> - -<% -} -if (form.getWizardStep() == WizardStep.SHOW_PARTICIPANTS) -{ - List groups = DesignerController.getStudyDefinition(form, user, container).getGroups(); - int nParticipants = 0; - for (GWTCohort group : groups) - nParticipants += group.getCount(); -%> - This study defines <%=DesignerController.getStudyDefinition(form, user, container).getGroups().size()%> cohorts with a total of - <%=nParticipants%> subjects. -
- To initiate this study, you will need to fill out an excel workbook with the subject id and cohort for each <%=h(species)%>. -
    -
  • <%=link("Download the Excel Workbook with subjects").href("#downloadSubjects").onClick("sendFormTo('study-designer-getParticipantExcel.view')").clearClasses()%>
  • -
  • Save the workbook on your computer
  • -
  • Fill in identifiers for each subject in the study
  • -
  • You can also add new columns to this list containing other information about each subject.
  • -
  • Upload your own set of subject data by pasting spreadsheet data in the following text field. The first - row of the data must contain the following columns.
  • -
      -
    • SubjectId -- The id for a particular <%=h(species)%>.
    • -
    • Cohort -- The cohort name. Must be a cohort in the study design
    • -
    • StartDate -- The date this subject started the study (Day 0)
    • -
    • Other columns may be added as well
    • -
    -
-
<% - %> - - The correct number of participants should be supplied for each cohort.
- -
- <%= generateBackButton() %> - <% if (form.isContainsWarnings()) {%> - <%= button("Ignore Warnings and Continue").submit(true).onClick("form.ignoreWarnings.value = 'true';form.submit();") %> - <%}%> - <%= button("Next").submit(true) %>  <%= button("Cancel").href(cancelUrl) %> -<% -} -if (form.getWizardStep() == WizardStep.UPLOAD_PARTICIPANTS) -{ -%> - You can upload your own set of subject data by pasting spreadsheet data in the following text field. The first - row of the data must contain the following columns. -
    -
  • SubjectId -- The id for a particular <%=h(species)%>.
  • -
  • Cohort -- The cohort name. Must be a cohort in the study design
  • -
- Other columns may be added. The correct number of participants should be supplied for each cohort.
- -
- <%= generateBackButton() %> <% if (form.isContainsWarnings()) {%> - <%= button("Ignore Warnings and Continue").submit(true).onClick("form.ignoreWarnings.value = 'true';form.submit();") %> - <%}%> - <%= button("Next").submit(true) %>  <%= button("Cancel").href(cancelUrl) %><% -} -if (form.getWizardStep() == WizardStep.CONFIRM) -{ - List groups = DesignerController.getStudyDefinition(form, user, container).getGroups(); - int nParticipants = 0; - for (GWTCohort group : groups) - nParticipants += group.getCount(); -%> -You are about to create a study folder with the following settings: -
    -
  • Folder Name: <%=h(form.getFolderName())%>
  • -
  • Start Date: <%=formatDate(form.getBeginDate())%>
  • -
  • Subjects: <%=DesignerController.getParticipants().size()%> <% - if (nParticipants != DesignerController.getParticipants().size()) { %> - Warning: Study design called for <%=nParticipants%> subjects. - <%} - %>
  • -
  • Specimens: <%=DesignerController.getSpecimens().size()%>
  • -
-
-<%= generateBackButton() %> - <%= button("Finish").submit(true) %>  <%= button("Cancel").href(cancelUrl) %> -<% -} - -if (form.getWizardStep() != WizardStep.UPLOAD_PARTICIPANTS && - form.getWizardStep() != WizardStep.SHOW_PARTICIPANTS) -{ -%> - -<% -} -%> - -
- - - diff --git a/study/src/org/labkey/study/designer/view/studyDesignSummary.jsp b/study/src/org/labkey/study/designer/view/studySummary.jsp similarity index 50% rename from study/src/org/labkey/study/designer/view/studyDesignSummary.jsp rename to study/src/org/labkey/study/designer/view/studySummary.jsp index 13130d84613..260bcb5313f 100644 --- a/study/src/org/labkey/study/designer/view/studyDesignSummary.jsp +++ b/study/src/org/labkey/study/designer/view/studySummary.jsp @@ -15,23 +15,14 @@ * limitations under the License. */ %> -<%@ page import="gwt.client.org.labkey.study.designer.client.model.GWTAntigen" %> -<%@ page import="gwt.client.org.labkey.study.designer.client.model.GWTCohort" %> -<%@ page import="gwt.client.org.labkey.study.designer.client.model.GWTImmunogen" %> -<%@ page import="gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition" %> -<%@ page import="org.labkey.api.action.SpringActionController" %> <%@ page import="org.labkey.api.attachments.Attachment" %> <%@ page import="org.labkey.api.data.Container" %> <%@ page import="org.labkey.api.security.User" %> <%@ page import="org.labkey.api.security.permissions.AdminPermission" %> -<%@ page import="org.labkey.api.security.permissions.ReadPermission" %> <%@ page import="org.labkey.api.study.Study" %> <%@ page import="org.labkey.api.util.HtmlString" %> <%@ page import="org.labkey.api.view.ActionURL" %> <%@ page import="org.labkey.study.controllers.StudyController" %> -<%@ page import="org.labkey.study.controllers.designer.DesignerController" %> -<%@ page import="org.labkey.study.designer.StudyDesignInfo" %> -<%@ page import="org.labkey.study.designer.StudyDesignManager" %> <%@ page import="org.labkey.study.model.StudyManager" %> <%@ page import="java.util.List" %> <%@ page extends="org.labkey.api.jsp.JspBase" %> @@ -40,89 +31,24 @@ User user = getUser(); Study study = StudyManager.getInstance().getStudy(c); if (null == study) - { %> - No study is active in the current container.
- <%= button("Create Study").href(new ActionURL(StudyController.ManageStudyPropertiesAction.class, c)) %> -<% - return; - } - - // issue 21432: only create study design as admin if the label is not already in use - StudyDesignInfo info = StudyDesignManager.get().getDesignForStudy(study); - boolean designExistsForLabel = StudyDesignManager.get().getStudyDesign(c, study.getLabel()) != null; - if (info == null && c.hasPermission(user, AdminPermission.class) && !designExistsForLabel) { - try (var ignored = SpringActionController.ignoreSqlUpdates()) - { - info = StudyDesignManager.get().ensureDesignForStudy(user, study, true); - } - } - - if (null == info) - {%> - No protocol has been registered for this study.<% - return; - } - //Shouldn't happen, but being defensive - if (!info.getContainer().equals(study.getContainer()) && !info.getContainer().hasPermission(getUser(), ReadPermission.class)) - {%> - Study protocol is in another folder you do not have permission to read. -<% - - } - GWTStudyDefinition revision = StudyDesignManager.get().getGWTStudyDefinition(user, info.getContainer(), info); %> + No study is active in the current container.
+ <%= button("Create Study").href(new ActionURL(StudyController.ManageStudyPropertiesAction.class, c)) %> <% - if (null == study.getDescription() && null != revision.getDescription()) //No study description. Generate one from the study design - { -%> -This study was created from a vaccine study protocol with the following description. -
- <%=h(revision.getDescription(), true)%> -
-Immunogens: <% - String sep = ""; - for (GWTImmunogen immunogen : revision.getImmunogens()) - { - out.print(unsafe(sep)); - out.print(h(immunogen.getName())); - String antigenSep = ""; - for (GWTAntigen antigen : immunogen.getAntigens()) - { - out.print(unsafe(antigenSep)); - out.print(h(antigen.getName())); - antigenSep = ","; - } - sep = ", "; - } -%>
-Cohorts: <% - sep = ""; - for (GWTCohort cohort : revision.getGroups()) - { - out.print(unsafe(sep)); - out.print(h(cohort.getName() + " (" + cohort.getCount() + ")")); - sep = ", "; + return; } %> -
+ <% - ActionURL url = new ActionURL(DesignerController.DesignerAction.class, info.getContainer()); - url.replaceParameter("studyId", info.getStudyId()); + boolean isAdmin = c.hasPermission(user, AdminPermission.class); + HtmlString descriptionHtml = study.getDescriptionHtml(); + String investigator = study.getInvestigator(); + String grant = study.getGrant(); + List protocolDocs = study.getProtocolDocuments(); + ActionURL editMetadataURL = new ActionURL(StudyController.ManageStudyPropertiesAction.class, c); + editMetadataURL.addReturnURL(getActionURL()); %> -<%=link("View Complete Protocol", url)%> -<% - } - else - { - boolean isAdmin = c.hasPermission(user, AdminPermission.class); - HtmlString descriptionHtml = study.getDescriptionHtml(); - String investigator = study.getInvestigator(); - String grant = study.getGrant(); - List protocolDocs = study.getProtocolDocuments(); - ActionURL editMetadataURL = new ActionURL(StudyController.ManageStudyPropertiesAction.class, c); - editMetadataURL.addReturnURL(getActionURL()); - %> @@ -184,9 +110,10 @@ This study was created from a vaccine study protocol with the following descript <% - if (isAdmin) - { %> -<%=link("Edit", editMetadataURL)%> -<% } - } + if (isAdmin) + { +%> + <%=link("Edit", editMetadataURL)%> +<% + } %> \ No newline at end of file diff --git a/study/src/org/labkey/study/model/StudyImpl.java b/study/src/org/labkey/study/model/StudyImpl.java index 3df101d3e43..05025b5f68a 100644 --- a/study/src/org/labkey/study/model/StudyImpl.java +++ b/study/src/org/labkey/study/model/StudyImpl.java @@ -16,7 +16,6 @@ package org.labkey.study.model; -import gwt.client.org.labkey.study.designer.client.model.GWTStudyDefinition; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -77,8 +76,6 @@ import org.labkey.api.wiki.WikiRenderingService; import org.labkey.study.StudyModule; import org.labkey.study.controllers.StudyController; -import org.labkey.study.designer.StudyDesignInfo; -import org.labkey.study.designer.StudyDesignManager; import org.labkey.study.query.StudyQuerySchema; import java.io.IOException; @@ -297,6 +294,7 @@ public Collection getCohorts(User user) @Override public boolean hasGWTStudyDesign(Container c, User user) { +/* StudyDesignManager manager = StudyDesignManager.get(); StudyDesignInfo info = manager.getDesignForStudy(this); if (info != null) @@ -309,6 +307,7 @@ public boolean hasGWTStudyDesign(Container c, User user) !def.getAssaySchedule().getAssays().isEmpty() || !def.getAssaySchedule().getTimepoints().isEmpty() ); } +*/ return false; } diff --git a/study/src/org/labkey/study/model/StudyManager.java b/study/src/org/labkey/study/model/StudyManager.java index f9285886051..29722df0a12 100644 --- a/study/src/org/labkey/study/model/StudyManager.java +++ b/study/src/org/labkey/study/model/StudyManager.java @@ -2701,7 +2701,6 @@ public void deleteAllStudyData(Container c, User user) try (Transaction transaction = scope.ensureTransaction()) { - StudyDesignManager.get().deleteStudyDesigns(c, deletedTables); StudyDesignManager.get().deleteStudyDesignLookupValues(c, deletedTables); for (DatasetDefinition dsd : dsds) diff --git a/study/src/org/labkey/study/view/VaccineStudyWebPart.java b/study/src/org/labkey/study/view/VaccineStudyWebPart.java deleted file mode 100644 index 38a2ac99e68..00000000000 --- a/study/src/org/labkey/study/view/VaccineStudyWebPart.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2011-2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.labkey.study.view; - -import org.labkey.api.view.JspView; - -/** - * User: markigra - * Date: 11/17/11 - * Time: 3:43 PM - */ -public class VaccineStudyWebPart extends JspView -{ - enum Panels { - VACCINE("Vaccine Design"), - IMMUNIZATIONS("Immunization Schedule"), - ASSAYS("Assay Schedule"); - - private String _title; - Panels(String title) - { - _title = title; - } - - String getTitle() - { - return _title; - } - - } - - public VaccineStudyWebPart(Model model) - { - super("/org/labkey/study/view/vaccineStudy.jsp", model); - assert (null != model.getStudyId() && 0 != model.getStudyId()); - String title = null; - if (null != model.getPanel()) - { - Panels p = Panels.valueOf(model.getPanel()); - if (null != p) - title = p.getTitle(); - } - if (null == title) - title = "Vaccine Study Protocol"; - - setTitle(title); - } - - - public static class Model - { - private String _panel; - private boolean _editMode; - private Integer _studyId; - private String _finishURL; - - public String getPanel() - { - return _panel; - } - - public void setPanel(String panel) - { - _panel = panel; - } - - public boolean isEditMode() - { - return _editMode; - } - - public void setEditMode(boolean editMode) - { - _editMode = editMode; - } - - public Integer getStudyId() - { - return _studyId; - } - - public void setStudyId(Integer studyId) - { - _studyId = studyId; - } - - public String getFinishURL() - { - return _finishURL; - } - - public void setFinishURL(String finishURL) - { - _finishURL = finishURL; - } - } -} diff --git a/study/src/org/labkey/study/view/vaccineStudy.jsp b/study/src/org/labkey/study/view/vaccineStudy.jsp deleted file mode 100644 index b1d1a3f6e3a..00000000000 --- a/study/src/org/labkey/study/view/vaccineStudy.jsp +++ /dev/null @@ -1,79 +0,0 @@ -<% -/* - * Copyright (c) 2011-2018 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -%> -<%@ page import="org.labkey.api.data.Container" %> -<%@ page import="org.labkey.api.security.permissions.AdminPermission" %> -<%@ page import="org.labkey.api.security.permissions.UpdatePermission" %> -<%@ page import="org.labkey.api.settings.OptionalFeatureService" %> -<%@ page import="org.labkey.api.study.Study" %> -<%@ page import="org.labkey.api.study.Visit" %> -<%@ page import="org.labkey.api.view.HttpView" %> -<%@ page import="org.labkey.api.view.NotFoundException" %> -<%@ page import="org.labkey.api.view.ViewContext" %> -<%@ page import="org.labkey.api.view.template.ClientDependencies" %> -<%@ page import="org.labkey.study.designer.StudyDesignManager" %> -<%@ page import="org.labkey.study.model.StudyImpl" %> -<%@ page import="org.labkey.study.model.StudyManager" %> -<%@ page import="org.labkey.study.view.StudyGWTView" %> -<%@ page import="org.labkey.study.view.VaccineStudyWebPart" %> -<%@ page import="java.util.HashMap" %> -<%@ page import="java.util.Map" %> -<%@ page extends="org.labkey.api.jsp.JspBase"%> -<%! - @Override - public void addClientDependencies(ClientDependencies dependencies) - { - dependencies.add("study/StudyVaccineDesign.css"); - } -%> -<% - HttpView me = HttpView.currentView(); - ViewContext context = getViewContext(); - Container c = getContainer(); - VaccineStudyWebPart.Model bean = (VaccineStudyWebPart.Model) me.getModelBean(); - - Map params = new HashMap<>(); - params.put("studyId", Integer.toString(bean.getStudyId())); - - //In the web part we always show the latest revision - Integer revInteger = StudyDesignManager.get().getLatestRevisionNumber(c, bean.getStudyId()); - if (revInteger == null) - throw new NotFoundException("No revision found for Study ID: " + bean.getStudyId()); - - params.put("revision", Integer.toString(revInteger)); - params.put("edit", context.hasPermission(UpdatePermission.class) && bean.isEditMode() ? "true" : "false"); - boolean canEdit = OptionalFeatureService.get().isFeatureEnabled(Study.GWT_STUDY_DESIGN) && context.hasPermission(UpdatePermission.class); - params.put("canEdit", Boolean.toString(canEdit)); - //Can't create repository from web part - params.put("canCreateRepository", Boolean.FALSE.toString()); - - StudyImpl study = StudyManager.getInstance().getStudy(getContainer()); - boolean canAdmin = context.hasPermission(AdminPermission.class) && null != study; - params.put("canAdmin", Boolean.toString(canAdmin)); - params.put("canCreateTimepoints", Boolean.toString(canAdmin && study.getVisits(Visit.Order.DISPLAY).isEmpty())); - - params.put("panel", bean.getPanel()); //bean.getPanel()); - if (null != bean.getFinishURL()) - params.put("finishURL", bean.getFinishURL()); - - StudyGWTView innerView = new StudyGWTView(gwt.client.org.labkey.study.designer.client.Designer.class, params); - - response.setContentType("text/css"); -%> -<% -include(innerView, out); -%> From b5965e430b8cb1014bf5c3b554b16f9a37558f69 Mon Sep 17 00:00:00 2001 From: lum Date: Sat, 23 Nov 2024 16:01:39 -0800 Subject: [PATCH 2/3] delete GWT study design classes, final cleanup --- .gitattributes | 37 - api/src/org/labkey/api/study/Study.java | 2 - study/gwtsrc/gwt/StudyApplication.gwt.xml | 11 - .../org/labkey/study/StudyApplication.java | 122 --- .../designer/client/ActivatingLabel.java | 158 ---- .../study/designer/client/AssayPanel.java | 397 ---------- .../client/DeprecatedMessagePanel.java | 55 -- .../designer/client/DescriptionWidget.java | 34 - .../study/designer/client/Designer.java | 470 ----------- .../client/DesignerLookupConfigDialog.java | 114 --- .../study/designer/client/EditableGrid.java | 272 ------- .../study/designer/client/GridModel.java | 35 - .../study/designer/client/GroupGrid.java | 171 ---- .../study/designer/client/GroupPanel.java | 43 -- .../designer/client/ImmunizationPanel.java | 387 ---------- .../designer/client/ListChangeListener.java | 30 - .../study/designer/client/OverviewPanel.java | 234 ------ .../designer/client/SampleMeasurePanel.java | 170 ---- .../study/designer/client/ScheduleGrid.java | 509 ------------ .../client/StudyDefinitionService.java | 39 - .../client/StudyDefinitionServiceAsync.java | 49 -- .../study/designer/client/VaccinePanel.java | 727 ------------------ .../client/model/AbstractXMLSavable.java | 81 -- .../designer/client/model/GWTAdjuvant.java | 69 -- .../designer/client/model/GWTAntigen.java | 114 --- .../client/model/GWTAssayDefinition.java | 87 --- .../designer/client/model/GWTAssayNote.java | 76 -- .../client/model/GWTAssaySchedule.java | 195 ----- .../designer/client/model/GWTCohort.java | 79 -- .../client/model/GWTImmunization.java | 130 ---- .../client/model/GWTImmunizationSchedule.java | 213 ----- .../designer/client/model/GWTImmunogen.java | 149 ---- .../client/model/GWTSampleMeasure.java | 122 --- .../client/model/GWTStudyDefinition.java | 405 ---------- .../client/model/GWTStudyDesignVersion.java | 129 ---- .../designer/client/model/GWTTimepoint.java | 189 ----- .../study/designer/client/model/Schedule.java | 40 - .../client/model/VaccineComponent.java | 65 -- .../designer/client/model/XMLSavable.java | 32 - .../study/designer/client/model/XMLUtils.java | 111 --- study/src/org/labkey/study/StudyModule.java | 8 - .../org/labkey/study/view/StudyGWTView.java | 44 -- 42 files changed, 6404 deletions(-) delete mode 100644 study/gwtsrc/gwt/StudyApplication.gwt.xml delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/StudyApplication.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/ActivatingLabel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/AssayPanel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/DeprecatedMessagePanel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/DescriptionWidget.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/Designer.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/DesignerLookupConfigDialog.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/EditableGrid.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/GridModel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/GroupGrid.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/GroupPanel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/ImmunizationPanel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/ListChangeListener.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/OverviewPanel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/SampleMeasurePanel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/ScheduleGrid.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/StudyDefinitionService.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/StudyDefinitionServiceAsync.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/VaccinePanel.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/AbstractXMLSavable.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAdjuvant.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAntigen.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAssayDefinition.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAssayNote.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAssaySchedule.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTCohort.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTImmunization.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTImmunizationSchedule.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTImmunogen.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTSampleMeasure.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTStudyDefinition.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTStudyDesignVersion.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTTimepoint.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/Schedule.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/VaccineComponent.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/XMLSavable.java delete mode 100644 study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/XMLUtils.java delete mode 100644 study/src/org/labkey/study/view/StudyGWTView.java diff --git a/.gitattributes b/.gitattributes index 7953a0c8301..e661498e54e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2648,43 +2648,6 @@ search/src/org/labkey/search/view/search.jsp -text search/src/org/labkey/search/view/SearchWebPart.java -text search/src/org/labkey/search/view/SearchWebPartFactory.java -text search/src/org/labkey/search/view/testJson.jsp -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/ActivatingLabel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/AssayPanel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/DeprecatedMessagePanel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/DescriptionWidget.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/Designer.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/DesignerLookupConfigDialog.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/EditableGrid.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/GridModel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/GroupGrid.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/GroupPanel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/ImmunizationPanel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/ListChangeListener.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/AbstractXMLSavable.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAdjuvant.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAntigen.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAssayDefinition.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAssayNote.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTAssaySchedule.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTCohort.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTImmunization.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTImmunizationSchedule.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTImmunogen.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTSampleMeasure.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTStudyDefinition.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTStudyDesignVersion.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/GWTTimepoint.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/Schedule.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/VaccineComponent.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/XMLSavable.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/model/XMLUtils.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/OverviewPanel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/SampleMeasurePanel.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/ScheduleGrid.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/StudyDefinitionService.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/StudyDefinitionServiceAsync.java -text -study/gwtsrc/gwt/client/org/labkey/study/designer/client/VaccinePanel.java -text -study/gwtsrc/gwt/StudyApplication.gwt.xml -text study/module.properties -text study/resources/schemas/dbscripts/postgresql/study-create.sql -text study/resources/schemas/dbscripts/postgresql/study-drop.sql -text diff --git a/api/src/org/labkey/api/study/Study.java b/api/src/org/labkey/api/study/Study.java index b1050480a29..850083d1455 100644 --- a/api/src/org/labkey/api/study/Study.java +++ b/api/src/org/labkey/api/study/Study.java @@ -37,8 +37,6 @@ */ public interface Study extends StudyEntity { - public static final String GWT_STUDY_DESIGN = "GWTStudyDesign"; - String getShortName(); Collection getVisits(Visit.Order order); diff --git a/study/gwtsrc/gwt/StudyApplication.gwt.xml b/study/gwtsrc/gwt/StudyApplication.gwt.xml deleted file mode 100644 index 04afc8f15a4..00000000000 --- a/study/gwtsrc/gwt/StudyApplication.gwt.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/study/gwtsrc/gwt/client/org/labkey/study/StudyApplication.java b/study/gwtsrc/gwt/client/org/labkey/study/StudyApplication.java deleted file mode 100644 index 15eca001754..00000000000 --- a/study/gwtsrc/gwt/client/org/labkey/study/StudyApplication.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2010-2019 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package gwt.client.org.labkey.study; - -import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.RunAsyncCallback; -import com.google.gwt.user.client.ui.RootPanel; -import org.labkey.api.gwt.client.util.ErrorDialogAsyncCallback; -import org.labkey.api.gwt.client.util.PropertyUtil; - -import java.util.HashSet; -import java.util.Set; - -/** - * User: matthewb - * Date: Mar 31, 2010 - * Time: 1:59:56 PM - */ -public class StudyApplication implements EntryPoint -{ - /** - * As of 2.4.0, the GWT compiler NPEs if you pass an enum value in to GWT.runAsync(). Therefore, this is enum-like - * but not an actual enum anymore. - */ - public abstract static class GWTModule implements RunAsyncCallback - { - public final String className; - - private static final Set MODULES = new HashSet<>(); - - static - { - MODULES.add(new StudyDesigner()); - } - - GWTModule(String clss) - { - this.className = clss; - } - - abstract EntryPoint getEntryPoint(); - - // - // RunAsyncCallback - // - @Override - public void onFailure(Throwable caught) - { - ErrorDialogAsyncCallback.showDialog(caught, "Failed to load code for module: " + getClass()); - } - - public static Set values() - { - return MODULES; - } - } - - public static class StudyDesigner extends GWTModule - { - public StudyDesigner() - { - super("gwt.client.org.labkey.study.designer.client.Designer"); - } - - @Override - public void onSuccess() - { - new gwt.client.org.labkey.study.designer.client.Designer().onModuleLoad(); - } - - @Override - EntryPoint getEntryPoint() - { - return new gwt.client.org.labkey.study.designer.client.Designer(); - } - } - - - public static RootPanel getRootPanel() - { - String name = PropertyUtil.getServerProperty("RootPanel"); - if (null == name) - name = "gwt.StudyApplication-Root"; - return RootPanel.get(name); - } - - - @Override - public void onModuleLoad() - { - RootPanel panel = getRootPanel(); - if (null != panel) - { - panel.getElement().setInnerHTML(""); - } - - final String moduleName = PropertyUtil.getServerProperty("GWTModule"); - - if ("StudyDesigner".equalsIgnoreCase(moduleName)) - { - GWT.runAsync(new StudyDesigner()); - } - else - { - throw new IllegalArgumentException("Unknown module: " + moduleName); - } - } -} diff --git a/study/gwtsrc/gwt/client/org/labkey/study/designer/client/ActivatingLabel.java b/study/gwtsrc/gwt/client/org/labkey/study/designer/client/ActivatingLabel.java deleted file mode 100644 index c0d33265ee2..00000000000 --- a/study/gwtsrc/gwt/client/org/labkey/study/designer/client/ActivatingLabel.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2010-2013 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package gwt.client.org.labkey.study.designer.client; - -import com.google.gwt.user.client.ui.*; -import org.labkey.api.gwt.client.util.StringUtils; - - -/** - * User: Mark Igra - * Date: Dec 17, 2006 - * Time: 2:50:47 PM - */ -public class ActivatingLabel extends Composite implements SourcesFocusEvents, SourcesChangeEvents, ChangeListener, FocusListener, HasText -{ - FocusPanel fp = new FocusPanel(); - HTML l = new HTML(); - String emptyText = "Click to edit"; - Widget widget = null; - FocusListenerCollection focusListeners = new FocusListenerCollection(); - ChangeListenerCollection changeListeners = new ChangeListenerCollection(); - - - public ActivatingLabel(Widget activated, String textWhenEmpty) - { - widget = activated; - emptyText = textWhenEmpty; - - assert widget instanceof HasFocus; - assert widget instanceof SourcesChangeEvents; - assert widget instanceof HasText; - - initWidget(fp); - fp.addFocusListener(this); - ((HasFocus) widget).addFocusListener(this); - ((SourcesChangeEvents) widget).addChangeListener(this); - l.setWordWrap(true); - updateLabelText(((HasText) widget).getText()); - fp.setWidget(l); - } - - public ActivatingLabel() - { - this(new TextArea(), "Click to edit"); - } - - @Override - public Widget getWidget() - { - return widget; - } - - @Override - public String getText() - { - return ((HasText) widget).getText(); - } - - @Override - public void setText(String text) - { - l.setHTML(StringUtils.filter(text, true)); - ((HasText) widget).setText(text); - updateLabelText(text); - } - - private void updateLabelText(String text) - { - text = StringUtils.trimToNull(text); - if (null == text) - { - l.setText(emptyText); - l.setStyleName("empty"); - } - else - { - l.setHTML(StringUtils.filter(text, true)); - l.setStyleName("gwt-Label"); - } - } - - @Override - public void addFocusListener(FocusListener listener) - { - focusListeners.add(listener); - } - - @Override - public void removeFocusListener(FocusListener listener) - { - focusListeners.remove(listener); - } - - @Override - public void addChangeListener(ChangeListener listener) - { - changeListeners.add(listener); - } - - @Override - public void removeChangeListener(ChangeListener listener) - { - changeListeners.remove(listener); - } - - @Override - public void onChange(Widget sender) - { - updateLabelText(((HasText) widget).getText()); - changeListeners.fireChange(this); - } - - @Override - public void onFocus(Widget sender) - { - if (sender.equals(fp)) - { - int labelHeight = l.getOffsetHeight(); - fp.setWidget(widget); - if (widget.getOffsetHeight() < labelHeight && !(widget.getOffsetHeight() <= 0)) - widget.setHeight((labelHeight + 8) + "px"); - ((HasFocus) widget).setFocus(true); - } - focusListeners.fireFocus(this); - } - - @Override - public void onLostFocus(Widget sender) - { - if (sender.equals(fp)) - return; - - //NOTE: On Firefox, onChange not necessarily fired on lost focus. - //Double check here. - String text = ((HasText) widget).getText(); - if (!text.equals(l.getText())) - { - changeListeners.fireChange(this); - updateLabelText(((HasText) widget).getText()); - } - fp.setWidget(l); - focusListeners.fireLostFocus(this); - } -} diff --git a/study/gwtsrc/gwt/client/org/labkey/study/designer/client/AssayPanel.java b/study/gwtsrc/gwt/client/org/labkey/study/designer/client/AssayPanel.java deleted file mode 100644 index 06196c04053..00000000000 --- a/study/gwtsrc/gwt/client/org/labkey/study/designer/client/AssayPanel.java +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Copyright (c) 2010-2018 LabKey Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package gwt.client.org.labkey.study.designer.client; - -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.*; -import org.labkey.api.gwt.client.util.StringUtils; -import gwt.client.org.labkey.study.designer.client.model.*; - -import java.util.List; - -/** - * User: Mark Igra - * Date: Dec 20, 2006 - * Time: 4:20:46 PM - */ -public class AssayPanel extends Composite -{ - GWTStudyDefinition studyDef; - GWTAssaySchedule assaySchedule; - Designer designer; - AssayGrid eg; - - public AssayPanel(Designer parent) - { - this.designer = parent; - this.studyDef = parent.getDefinition(); - this.assaySchedule = studyDef.getAssaySchedule(); - - eg = new AssayGrid(parent); - VerticalPanel vpanel = new VerticalPanel(); - - if (!designer.isReadOnly()) - { - final TextArea tbDescription = new TextArea(); - tbDescription.setWidth("100%"); - tbDescription.setVisibleLines(5); - tbDescription.setName("assayPlan"); //For easier testing - ActivatingLabel descriptionEditor = new ActivatingLabel(tbDescription, "Click to type assay plan here"); - if (null != assaySchedule.getDescription()) - descriptionEditor.setText(assaySchedule.getDescription()); - descriptionEditor.addChangeListener(new ChangeListener() { - @Override - public void onChange(Widget sender) { - assaySchedule.setDescription(((HasText) sender).getText()); - designer.setDirty(true); - } - }); - vpanel.add(descriptionEditor); - vpanel.add(eg); - } - else - { - if (eg.getCategoryRowCount() == 0 && assaySchedule.getTimepoints().size() == 0) - { - String html = "No assays have been scheduled."; - if (designer.canEdit) - html += "
Click the edit button to add assays."; - vpanel.add(new HTML(html)); - } - else - { - HTML description = new HTML(StringUtils.filter(assaySchedule.getDescription(), true)); - vpanel.add(description); - vpanel.add(eg); - } - } - - eg.updateAll(); - initWidget(vpanel); - } - - public void updateAll() - { - eg.updateAll(); - } - - public boolean validate() - { - return true; - } - - class AssayGrid extends ScheduleGrid - { - private GWTAssayDefinition ghostAssayDefinition = null; - - AssayGrid(Designer designer) - { - super(assaySchedule, "Assay Schedule", designer); - DOM.setAttribute(getElement(), "id", "AssayGrid"); - setReadOnly(designer.isReadOnly()); - } - - @Override - int getCategoryColumnCount() - { - return 2; //Assay, Lab - } - - @Override - int getCategoryRowCount() - { - return assaySchedule.getAssays().size(); - } - - - @Override - Widget getCategoryHeader(int col) - { - if (col == 0) - return new Label("Assay"); - else - return new Label("Lab"); - } - - @Override - Widget getCategoryWidget(int categoryIndex, int col) - { - if (categoryIndex >= assaySchedule.getAssays().size()) - return null; - - if (col == 0) - { - final GWTAssayDefinition ad = assaySchedule.getAssay(categoryIndex); - final Label lb = new Label(ad.getAssayName()); - return lb; - } - else - return getLabPicker(assaySchedule.getAssay(categoryIndex)); - } - - @Override - Object getCategoryValue(int categoryIndex, int col) - { - if (categoryIndex >= assaySchedule.getAssays().size()) - return null; - - if (col == 0) - return assaySchedule.getAssay(categoryIndex); - else - return assaySchedule.getAssay(categoryIndex).getLab(); - } - - @Override - Object getEventValue(int categoryIndex, GWTTimepoint tp) - { - if (categoryIndex >= assaySchedule.getAssays().size()) - return null; - - GWTAssayDefinition assayDefinition = assaySchedule.getAssay(categoryIndex); - return assaySchedule.getAssayPerformed(assayDefinition, tp); - } - - @Override - Widget getGhostCategoryWidget(int col) - { - if (col == 0) - { - return new AssayListBox(); - } - return new Label(""); - } - - private class AssayListBox extends ListBox implements ChangeListener - { - private ChangeListenerCollection externalListeners = new ChangeListenerCollection(); - AssayListBox() - { - //Handle changes locally and may or may not fire external listeners depending - //on user confirmation - super.addChangeListener(this); - addItem("