Skip to content

Commit

Permalink
Cleanup SEDStacker Code
Browse files Browse the repository at this point in the history
Reformatting, breaking up long methods, etc.
  • Loading branch information
Erik H committed Nov 16, 2015
1 parent dffb46b commit 9f9a795
Show file tree
Hide file tree
Showing 7 changed files with 541 additions and 455 deletions.
36 changes: 16 additions & 20 deletions iris-common/src/main/java/cfa/vo/sherpa/SherpaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import cfa.vo.interop.SAMPController;
import cfa.vo.interop.SAMPFactory;
import cfa.vo.interop.SAMPMessage;

import org.apache.commons.lang.StringUtils;
import org.astrogrid.samp.Client;
import org.astrogrid.samp.Response;
import org.astrogrid.samp.client.SampException;
Expand All @@ -37,8 +39,9 @@
public class SherpaClient {

private SAMPController sampController;
private Map<String, AbstractModel> modelMap = new HashMap();
private Map<String, AbstractModel> modelMap = new HashMap<>();
private Integer stringCounter = 0;
private Map<String, Class> exceptions = new Exceptions();
// private String sherpaPublicId;

public SherpaClient(SAMPController controller) {
Expand Down Expand Up @@ -99,7 +102,6 @@ public FitResults fit(Data dataset, CompositeModel model, Stat stat, Method meth
Response response = sampController.callAndWait(sherpaPublicId, message.get(), 10);

return (FitResults) SAMPFactory.get(response.getResult(), FitResults.class);

}

public Data createData(String name) {
Expand Down Expand Up @@ -143,27 +145,24 @@ public Method getMethod(OptimizationMethod optMethod) {
public String findSherpa() throws SampException {
// if(sherpaPublicId==null)
String returnString = "";
try {
for(Entry<String, Client> entry : (Set<Entry<String, Client>>) sampController.getClientMap().entrySet())
if (entry.getValue().getMetadata().getName().toLowerCase().equals("sherpa")) {
returnString = entry.getValue().getId();
break;
}
if (!returnString.isEmpty()) {
return returnString;
} else {
throw new Exception();
try {
for(Entry<String, Client> entry : (Set<Entry<String, Client>>) sampController.getClientMap().entrySet())
if (entry.getValue().getMetadata().getName().toLowerCase().equals("sherpa")) {
returnString = entry.getValue().getId();
break;
}
} catch (Exception ex) {
throw new SampException("Cannot find Sherpa. If the problem persists, please refer to the troubleshooting section of the documentation.");
if (StringUtils.isEmpty(returnString)) {
throw new Exception();
}
return returnString;
} catch (Exception ex) {
throw new SampException("Cannot find Sherpa. If the problem persists, please refer to the troubleshooting section of the documentation.", ex);
}
}

public boolean isException(Response rspns) {
return !rspns.isOK();
}

private Map<String, Class> exceptions = new Exceptions();

public Exception getException(Response rspns) throws Exception {
try {
Expand Down Expand Up @@ -235,7 +234,4 @@ public SEDException(String msg) {
super(msg);
}
}



}
}
34 changes: 20 additions & 14 deletions sed-builder/src/main/java/cfa/vo/sed/builder/NEDImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,39 @@ public class NEDImporter {

public static final String NED_DATA_DEFAULT_ENDPOINT =
"http://vo.ned.ipac.caltech.edu/services/accessSED?REQUEST=getData&TARGETNAME=:targetName";

public NEDImporter() {}

public static Sed getSedFromName(String targetName) throws SegmentImporterException {
return getSedFromName(targetName, NED_DATA_DEFAULT_ENDPOINT);
}

public static Sed getSedFromName(String targetName, String endpoint) throws SegmentImporterException {

Sed sed;
try {
targetName = URLEncoder.encode(targetName, "UTF-8");
endpoint = endpoint.replace(":targetName", targetName);
URL nedUrl = new URL(endpoint);

Sed sed = Sed.read(nedUrl.openStream(), SedFormat.VOT);

if(sed.getNumberOfSegments()>0) {
Segment seg = sed.getSegment(0);

if(seg.createTarget().getPos()==null)
if(seg.createChar().createSpatialAxis().createCoverage().getLocation()!=null)
seg.createTarget().createPos().setValue(seg.getChar().getSpatialAxis().getCoverage().getLocation().getValue());
else
seg.createTarget().createPos().setValue(new DoubleParam[]{new DoubleParam(Double.NaN), new DoubleParam(Double.NaN)});
}
return sed;

sed = Sed.read(nedUrl.openStream(), SedFormat.VOT);
} catch (Exception ex) {
throw new SegmentImporterException(ex);
}

if (sed.getNumberOfSegments() > 0) {
Segment seg = sed.getSegment(0);
if (seg.createTarget().getPos() == null) {
if (seg.createChar().createSpatialAxis().createCoverage().getLocation() != null) {
seg.createTarget().createPos()
.setValue(seg.getChar().getSpatialAxis().getCoverage().getLocation().getValue());
} else {
seg.createTarget().createPos()
.setValue(new DoubleParam[] { new DoubleParam(Double.NaN), new DoubleParam(Double.NaN) });
}
}
}

return sed;
}

// public static Sed getError() throws SegmentImporterException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,24 @@
import java.beans.PropertyChangeSupport;

/**
*
*
* @author olaurino
*/
public class Configuration {

private RedshiftConfiguration redshiftConfiguration = new RedshiftConfiguration();

public static final String PROP_REDSHIFTCONFIGURATION = "redshiftConfiguration";
public static final String PROP_NORMCONFIGURATION = "normConfiguration";
public static final String PROP_STACKCONFIGURATION = "stackConfiguration";

/**
* Get the value of redshiftConfiguration
*
* @return the value of redshiftConfiguration
*/
public RedshiftConfiguration getRedshiftConfiguration() {
return redshiftConfiguration;
}

/**
* Set the value of redshiftConfiguration
*
* @param redshiftConfiguration new value of redshiftConfiguration
*/
public void setRedshiftConfiguration(RedshiftConfiguration redshiftConfiguration) {
RedshiftConfiguration oldRedshiftConfiguration = this.redshiftConfiguration;
this.redshiftConfiguration = redshiftConfiguration;
propertyChangeSupport.firePropertyChange(PROP_REDSHIFTCONFIGURATION, oldRedshiftConfiguration, redshiftConfiguration);
}
private RedshiftConfiguration redshiftConfiguration = new RedshiftConfiguration();
private NormalizationConfiguration normConfiguration = new NormalizationConfiguration();
private StackConfiguration stackConfiguration = new StackConfiguration();

private transient final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

/**
* Add PropertyChangeListener.
*
*
* @param listener
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
Expand All @@ -68,60 +52,74 @@ public void addPropertyChangeListener(PropertyChangeListener listener) {

/**
* Remove PropertyChangeListener.
*
*
* @param listener
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}

private NormalizationConfiguration normConfiguration = new NormalizationConfiguration();
/**
* Get the value of redshiftConfiguration
*
* @return the value of redshiftConfiguration
*/
public RedshiftConfiguration getRedshiftConfiguration() {
return redshiftConfiguration;
}

public static final String PROP_NORMCONFIGURATION = "normConfiguration";
/**
* Set the value of redshiftConfiguration
*
* @param redshiftConfiguration
* new value of redshiftConfiguration
*/
public void setRedshiftConfiguration(RedshiftConfiguration redshiftConfiguration) {
RedshiftConfiguration oldRedshiftConfiguration = this.redshiftConfiguration;
this.redshiftConfiguration = redshiftConfiguration;
propertyChangeSupport.firePropertyChange(PROP_REDSHIFTCONFIGURATION, oldRedshiftConfiguration,
redshiftConfiguration);
}

/**
* Get the value of normConfiguration
*
*
* @return the value of normConfiguration
*/
public NormalizationConfiguration getNormConfiguration() {
return normConfiguration;
return normConfiguration;
}

/**
* Set the value of normConfiguration
*
* @param normConfiguration new value of normConfiguration
*
* @param normConfiguration
* new value of normConfiguration
*/
public void setNormConfiguration(NormalizationConfiguration normConfiguration) {
NormalizationConfiguration oldNormConfiguration = this.normConfiguration;
this.normConfiguration = normConfiguration;
propertyChangeSupport.firePropertyChange(PROP_NORMCONFIGURATION, oldNormConfiguration, normConfiguration);
NormalizationConfiguration oldNormConfiguration = this.normConfiguration;
this.normConfiguration = normConfiguration;
propertyChangeSupport.firePropertyChange(PROP_NORMCONFIGURATION, oldNormConfiguration, normConfiguration);
}

private StackConfiguration stackConfiguration = new StackConfiguration();

public static final String PROP_STACKCONFIGURATION = "stackConfiguration";

/**
* Get the value of stackConfiguration
*
*
* @return the value of stackConfiguration
*/
public StackConfiguration getStackConfiguration() {
return stackConfiguration;
return stackConfiguration;
}

/**
* Set the value of stackConfiguration
*
* @param stackConfiguration new value of stackConfiguration
*
* @param stackConfiguration
* new value of stackConfiguration
*/
public void setStackConfiguration(StackConfiguration stackConfiguration) {
StackConfiguration oldStackConfiguration = this.stackConfiguration;
this.stackConfiguration = stackConfiguration;
propertyChangeSupport.firePropertyChange(PROP_STACKCONFIGURATION, oldStackConfiguration, stackConfiguration);
StackConfiguration oldStackConfiguration = this.stackConfiguration;
this.stackConfiguration = stackConfiguration;
propertyChangeSupport.firePropertyChange(PROP_STACKCONFIGURATION, oldStackConfiguration, stackConfiguration);
}


}
Loading

0 comments on commit 9f9a795

Please sign in to comment.