Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
ONYX-1754 org.obiba.onyx.baseUrl added and used when generating JNLP …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
ymarcon committed Mar 8, 2018
1 parent ebbf57a commit b341364
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ org.obiba.onyx.opal.soTimeout=
# Obiba realm: Agate url, application name and key
org.obiba.onyx.agate.url=
org.obiba.onyx.agate.name=
org.obiba.onyx.agate.key=
org.obiba.onyx.agate.key=

# Server base URL that can be explicitly set (in case of proxy issue)
org.obiba.onyx.baseUrl=
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public interface InstrumentService {
*/
public String getInstrumentInstallPath(InstrumentType type);

/**
* Get the base URL to inject in the JNLP files if default behaviour is not suitable (because of a proxy).
*
* @return
*/
public String getBaseUrl();

/**
* Get the instrument types for given workstation.
* @param workstation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public abstract class DefaultInstrumentServiceImpl extends PersistenceManagerAwa

private String instrumentsPath;

private String baseUrl;

private Map<String, InstrumentType> instrumentTypes;

private UserSessionService userSessionService;
Expand All @@ -48,6 +50,14 @@ public void setInstrumentsPath(String instrumentsPath) {
this.instrumentsPath = instrumentsPath;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getBaseUrl() {
return baseUrl;
}

public InstrumentType getInstrumentType(String name) {
return instrumentTypes.get(name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
/*******************************************************************************
* Copyright 2008(c) The OBiBa Consortium. All rights reserved.
*
*
* This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package org.obiba.onyx.jade.core.wicket.instrument;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
Expand Down Expand Up @@ -61,6 +54,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
* Get the input parameters that are from read-only sources and give the instructions to the operator:
* <ul>
Expand Down Expand Up @@ -144,7 +143,7 @@ protected void onUpdate(AjaxRequestTarget target) {
});
add(radioGroup);
radioGroup.setVisible(instrumentType.hasManualCaptureOutputParameters());
ListView radioList = new ListView<String>("radioItem", Arrays.asList(new String[] { AUTOMATIC, MANUAL })) {
ListView radioList = new ListView<String>("radioItem", Arrays.asList(new String[]{AUTOMATIC, MANUAL})) {

@Override
protected void populateItem(final ListItem item) {
Expand Down Expand Up @@ -193,20 +192,20 @@ public void onSkipUpdate(AjaxRequestTarget target) {
}

String errMessage = activeInstrumentRunService.updateReadOnlyInputParameterRunValue();
if(errMessage != null) error(errMessage);
if (errMessage != null) error(errMessage);

RepeatingView repeat = new RepeatingView("repeat");
add(repeat);

// get all the input run values that requires manual capture
boolean manualCaptureRequired = false;
for(InstrumentInputParameter param : instrumentType.getInputParameters(InstrumentParameterCaptureMethod.MANUAL)) {
for (InstrumentInputParameter param : instrumentType.getInputParameters(InstrumentParameterCaptureMethod.MANUAL)) {

final String paramCode = param.getCode();

// We don't want to display parameters that were manually entered by the user in the previous step.
// These will be automatically sent to the instrument.
if(param.getDataSource() != null) {
if (param.getDataSource() != null) {

manualCaptureRequired = true;

Expand All @@ -220,10 +219,10 @@ public Serializable getObject() {
ValueMap map = new ValueMap();
map.put("description", new MessageSourceResolvableStringModel(param.getLabel()).getObject());
Data data = runValue.getData(param.getDataType());
if(data != null && data.getValue() != null) {
if (data != null && data.getValue() != null) {
map.put("value", new SpringStringResourceModel(data.getValueAsString()).getString());
String unit = param.getMeasurementUnit();
if(unit == null) {
if (unit == null) {
unit = "";
}
map.put("unit", unit);
Expand All @@ -240,7 +239,7 @@ public Serializable getObject() {
}

public void saveManualOutputInstrumentRunValues() {
for(IModel<InstrumentRunValue> runValueModel : outputRunValueModels) {
for (IModel<InstrumentRunValue> runValueModel : outputRunValueModels) {
activeInstrumentRunService.update(runValueModel.getObject());
}
}
Expand All @@ -251,14 +250,14 @@ public void saveManualOutputInstrumentRunValues() {
public abstract void onInstrumentLaunch();

public boolean isSkipMeasurement() {
if(measures != null) {
if (measures != null) {
return measures.isSkipMeasurement();
}
return false;
}

public boolean isMeasureComplete() {
if(measures != null) {
if (measures != null) {
return measures.isMeasureComplete();
}
return false;
Expand All @@ -276,7 +275,7 @@ public AutomaticCaptureFragment(String id) {
new Model<ValueMap>(new ValueMap("name=" + instrumentType.getName())))));

String codebase = instrumentService.getInstrumentInstallPath(instrumentType);
final InstrumentLauncher launcher = new InstrumentLauncher(instrumentType, codebase);
final InstrumentLauncher launcher = new InstrumentLauncher(instrumentType, codebase, instrumentService.getBaseUrl());
startButton = new Link<Object>("start") {

@Override
Expand Down Expand Up @@ -338,13 +337,13 @@ public ManualOutputsFragment(String id) {

private DataField makeDataField(InstrumentOutputParameter param, final IModel<InstrumentRunValue> runValueModel) {
List<Data> choices = null;
if(param.getDataSource() == null) {
if (param.getDataSource() == null) {
choices = param.getAllowedValues();
}

DataField field;

if(choices != null && choices.size() > 0) {
if (choices != null && choices.size() > 0) {
field = new DataField("field", new InstrumentRunValueDataModel(runValueModel, param.getDataType()), param.getDataType(), choices, new IChoiceRenderer() {

public Object getDisplayValue(Object object) {
Expand All @@ -369,7 +368,7 @@ public boolean isRequired() {
}
};

if(param.getDataType().equals(DataType.TEXT) && (field.getField().getClass().equals(java.awt.TextField.class) || field.getField().getClass().equals(TextArea.class))) {
if (param.getDataType().equals(DataType.TEXT) && (field.getField().getClass().equals(java.awt.TextField.class) || field.getField().getClass().equals(TextArea.class))) {
field.getField().add(new DataValidator(new StringValidator.MaximumLengthValidator(2000), param.getDataType()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.servlet.ServletContext;

import com.google.common.base.Strings;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Resource;
import org.apache.wicket.ResourceReference;
Expand Down Expand Up @@ -47,10 +48,13 @@ public class InstrumentLauncher implements Serializable {

private final String instrumentCodeBase;

public InstrumentLauncher(InstrumentType instrument, String instrumentCodeBase) {
private final String baseUrl;

public InstrumentLauncher(InstrumentType instrument, String instrumentCodeBase, String baseUrl) {
super();
this.customProperties = instrument.getProperties();
this.instrumentCodeBase = instrumentCodeBase;
this.baseUrl = baseUrl;
}

@SuppressWarnings("serial")
Expand Down Expand Up @@ -120,8 +124,11 @@ public IResourceStream getResourceStream() {
}

private String makeUrl(String path) {
WebRequest wr = (WebRequest) RequestCycle.get().getRequest();
return wr.getHttpServletRequest().getRequestURL().append(path).toString();
if (Strings.isNullOrEmpty(baseUrl)) {
WebRequest wr = (WebRequest) RequestCycle.get().getRequest();
return wr.getHttpServletRequest().getRequestURL().append(path).toString();
}
return baseUrl + (baseUrl.endsWith("/") ? "" : "/") + path;
}

private class PropertiesVariableInterpolator extends VariableInterpolator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/t
<property name="sessionFactory" ref="sessionFactory" />
<property name="persistenceManager" ref="persistenceManager" />
<property name="instrumentsPath" value="${org.obiba.onyx.jade.instruments.codebase.path}"/>
<property name="baseUrl" value="${org.obiba.onyx.baseUrl}" />
<property name="instrumentTypes">
<bean class="org.obiba.onyx.jade.core.service.impl.InstrumentTypeFactoryBean" scope="singleton">
<property name="resourcePatterns">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
******************************************************************************/
package org.obiba.onyx.jade.core.wicket.instrument;

import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.apache.wicket.MarkupContainer;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.Before;
Expand Down Expand Up @@ -72,12 +68,16 @@ public void testPresenceOfManualButtonWhenManualCaptureAllowed() {
expect(activeInstrumentRunServiceMock.getInstrumentType()).andReturn(instrumentType).anyTimes();
expect(activeInstrumentRunServiceMock.updateReadOnlyInputParameterRunValue()).andReturn(null).anyTimes();
expect(activeInstrumentRunServiceMock.getInstrumentRun()).andReturn(new InstrumentRun()).anyTimes();
expect(instrumentServiceMock.getInstrumentInstallPath(instrumentType)).andReturn(null);
expect(instrumentServiceMock.getBaseUrl()).andReturn("");

replay(activeInstrumentRunServiceMock);
replay(instrumentServiceMock);

InstrumentLaunchPanel instrumentLaunchPanel = createInstrumentLaunchPanel();

verify(activeInstrumentRunServiceMock);
verify(instrumentServiceMock);

// Verify visibility of the "enter values manually" button (this implies the visibility of its parent).
AjaxLink manualButton = (AjaxLink) instrumentLaunchPanel.get("measures:manualCapture:manualButton");
Expand All @@ -94,12 +94,16 @@ public void testAbsenceOfManualButtonWhenManualCaptureNotAllowed() {
expect(activeInstrumentRunServiceMock.getInstrumentType()).andReturn(instrumentType).anyTimes();
expect(activeInstrumentRunServiceMock.updateReadOnlyInputParameterRunValue()).andReturn(null).anyTimes();
expect(activeInstrumentRunServiceMock.getInstrumentRun()).andReturn(new InstrumentRun());
expect(instrumentServiceMock.getInstrumentInstallPath(instrumentType)).andReturn(null);
expect(instrumentServiceMock.getBaseUrl()).andReturn("");

replay(activeInstrumentRunServiceMock);
replay(instrumentServiceMock);

InstrumentLaunchPanel instrumentLaunchPanel = createInstrumentLaunchPanel();

verify(activeInstrumentRunServiceMock);
verify(instrumentServiceMock);

// Verify invisibility of the "enter values manually" button. At least one of the following
// must be true: Either the button is itself invisible or its parent is (effectively making
Expand All @@ -115,12 +119,16 @@ public void testPresenceOfManualEntryDialog() {
expect(activeInstrumentRunServiceMock.getInstrumentType()).andReturn(instrumentType).anyTimes();
expect(activeInstrumentRunServiceMock.updateReadOnlyInputParameterRunValue()).andReturn(null).anyTimes();
expect(activeInstrumentRunServiceMock.getInstrumentRun()).andReturn(new InstrumentRun());
expect(instrumentServiceMock.getInstrumentInstallPath(instrumentType)).andReturn(null);
expect(instrumentServiceMock.getBaseUrl()).andReturn("");

replay(activeInstrumentRunServiceMock);
replay(instrumentServiceMock);

InstrumentLaunchPanel instrumentLaunchPanel = createInstrumentLaunchPanel();

verify(activeInstrumentRunServiceMock);
verify(instrumentServiceMock);

// Verify presence of manual entry dialog.
Dialog manualEntryDialog = (Dialog) instrumentLaunchPanel.get("measures:manualEntryDialog");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<property name="sessionFactory" ref="sessionFactory" />
<property name="persistenceManager" ref="persistenceManager" />
<property name="instrumentsPath" value="${org.obiba.onyx.jade.instruments.codebase.path}" />
<property name="baseUrl" value="${org.obiba.onyx.baseUrl}" />
<property name="instrumentTypes" ref="instrumentTypeFactory" />
</bean>

Expand Down

0 comments on commit b341364

Please sign in to comment.