/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ws.params;
import jalview.util.MessageManager;
import jalview.ws.api.ServiceWithParameters;
import java.util.ArrayList;
import java.util.List;
public class AutoCalcSetting
{
protected boolean autoUpdate;
protected WsParamSetI preset;
protected List jobArgset;
protected ServiceWithParameters service;
public AutoCalcSetting(ServiceWithParameters service2,
WsParamSetI preset2, List jobArgset2,
boolean autoUpdate2)
{
service = service2;
autoUpdate = autoUpdate2;
preset = preset2;
jobArgset = jobArgset2;
}
public boolean isAutoUpdate()
{
return autoUpdate;
}
public void setAutoUpdate(boolean autoUpdate)
{
this.autoUpdate = autoUpdate;
}
public WsParamSetI getPreset()
{
return preset;
}
public void setPreset(WsParamSetI preset)
{
// TODO: test if service URL is in presets
this.preset = preset;
}
public List getArgumentSet()
{
return jobArgset;
}
/**
* TODO: refactor to ServiceWithParameters ?
*
* @return characteristic URI for this service. The URI should reflect the
* type and version of this service, enabling the service client code
* to recover the correct client for this calculation.
*/
public String getServiceURI()
{
return service.getNameURI();
}
/**
* TODO: refactor to ServiceWithParameters ?
*
* return any concrete service endpoints associated with this calculation.
* built in services should return a zero length array
*
* @return
*/
public String[] getServiceURLs()
{
return new String[] { service.getUri() };
}
/**
* default WsParamFile generator method - clients with custom formats should
* override and implement their own
*
* @return stringified representation of the parameters for this setting
*/
public String getWsParamFile()
{
List opts = null;
if (jobArgset != null)
{
opts = jobArgset;
}
else
{
if (preset != null)
{
opts = preset.getArguments();
}
}
if (opts == null || opts.size() == 0)
{
return "";
}
StringBuffer pset = new StringBuffer();
for (ArgumentI ps : opts)
{
pset.append(ps.getName() + "\t" + ps.getValue());
pset.append("\n");
}
return pset.toString();
}
public ServiceWithParameters getService()
{
return service;
}
public void setService(ServiceWithParameters service)
{
this.service = service;
if (preset != null)
{
// check if we need to migrate preset to a new service URL
for (String url : preset.getApplicableUrls())
{
if (url.equals(service.getUri()))
{
// preset already verified
return;
}
}
WsParamSetI pr = service.getParamStore().getPreset(preset.getName());
// TODO: decide of this distinction between preset and args are needed.
//
// if (pr instanceof JabaPreset && preset instanceof JabaPreset)
// {
// // easy - Presets are identical (we assume)
// preset = pr;
// return;
// }
// this verifies that all arguments in the existing preset are the same as
// the parameters for the preset provided by the service parameter store.
// ie the LastUsed settings or a predefined preset.
List oldargs = new ArrayList<>(),
newargs = new ArrayList<>();
oldargs.addAll(preset.getArguments());
// need to compare parameters
for (ArgumentI newparg : pr.getArguments())
{
if (!oldargs.remove(newparg))
{
newargs.add(newparg);
}
}
if (oldargs.size() == 0 && newargs.size() == 0)
{
// exact match.
preset = pr;
return;
}
// Try even harder to migrate arguments.
throw new Error(MessageManager
.getString("error.parameter_migration_not_implemented_yet"));
}
}
}