Merge branch '13.2.1_delivery' into development

Former-commit-id: 723f0efba18c83c46d3b241dae678e81d2ac924d
This commit is contained in:
Steve Harris 2013-01-16 12:03:50 -06:00
commit 8c447659ff
58 changed files with 3525 additions and 738 deletions

View file

@ -578,6 +578,8 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
}
}
synchronized (timeManager) {
DataTime[] oldTimes = timeManager.frames;
int oldIdx = this.frameIndex;
if (info.setFrames) {
if (info.frameTimes != null) {
DataTime[] newTimes = Arrays.copyOf(info.frameTimes,
@ -594,6 +596,14 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
timeMatchingMap = new ConcurrentHashMap<AbstractVizResource<?, ?>, DataTime[]>(
info.timeMap);
}
FramesInfo currInfo = getFramesInfo();
FramesInfo oldInfo = new FramesInfo(oldTimes, oldIdx);
DataTime oldTime = oldInfo.getCurrentFrame();
DataTime currTime = currInfo.getCurrentFrame();
if ((oldTime != null && oldTime.equals(currTime) == false)
|| (currTime != null && currTime.equals(oldTime) == false)) {
notifyFrameChanged(oldTime, currTime);
}
}
}
@ -624,20 +634,8 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
* @param frame
*/
private void setFrameInternal(int frame) {
FramesInfo currInfo = getFramesInfo();
int frameIndex = currInfo.frameIndex;
if (frame != frameIndex) {
DataTime[] times = currInfo.frameTimes;
DataTime oldTime = null, newTime = null;
// Get the old and new time
if (times != null && frameIndex >= 0 && frameIndex < times.length) {
oldTime = times[frameIndex];
}
if (times != null && frame >= 0 && frame < times.length) {
newTime = times[frame];
}
this.frameIndex = frame;
notifyFrameChanged(oldTime, newTime);
}
}

View file

@ -828,19 +828,23 @@ public class D2DTimeMatcher extends AbstractTimeMatcher {
*/
public void changeTimeMatchBasis(AbstractVizResource<?, ?> resource) {
if (timeMatchBasis != resource) {
TimeMatchingConfiguration config = getConfiguration(resource
.getLoadProperties());
TimeCache timeCache = getTimeCache(resource);
if (timeMatchBasis != null) {
TimeMatchingConfiguration config = getConfiguration(timeMatchBasis
.getLoadProperties());
config.setTimeMatchBasis(false);
TimeCache timeCache = getTimeCache(timeMatchBasis);
timeCache.setTimes(null, null);
timeMatchBasis
.unregisterListener(timeMatchBasisDisposeListener);
}
timeMatchBasis = resource;
if (timeMatchBasis != null) {
TimeMatchingConfiguration config = getConfiguration(timeMatchBasis
.getLoadProperties());
config.setTimeMatchBasis(true);
TimeCache timeCache = getTimeCache(timeMatchBasis);
timeCache.setTimes(null, null);
timeMatchBasis.registerListener(timeMatchBasisDisposeListener);
}

View file

@ -47,8 +47,6 @@ import com.raytheon.viz.ui.HistoryList;
import com.raytheon.viz.ui.HistoryList.IHistoryListener;
import com.raytheon.viz.ui.UiPlugin;
import com.raytheon.viz.ui.UiUtil;
import com.raytheon.viz.ui.actions.LoadSerializedXml;
import com.raytheon.viz.ui.actions.SaveBundle;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.ui.editor.AbstractEditor;
@ -331,7 +329,6 @@ public class HistoryListDlg extends CaveSWTDialog {
}
private void loadAlterBundle(Bundle b) {
try {
String editorName = null;
if (b.getDisplays().length > 0) {
@ -347,12 +344,7 @@ public class HistoryListDlg extends CaveSWTDialog {
.clear();
}
LoadSerializedXml.loadTo(editor, b);
HistoryList.getInstance().addBundle(b);
} catch (VizException e) {
final String err = "Error loading bundle";
statusHandler.handle(Priority.PROBLEM, err, e);
}
ProcedureLoadJob.getInstance().enqueue(b, editor);
}
/**
@ -378,10 +370,7 @@ public class HistoryListDlg extends CaveSWTDialog {
return;
}
LoadSerializedXml.loadTo(editor, b);
Bundle currBundle = SaveBundle.extractCurrentBundle();
HistoryList.getInstance().refreshLatestBundle(currBundle);
ProcedureLoadJob.getInstance().enqueue(b, editor);
} catch (VizException e) {
statusHandler.handle(Priority.SIGNIFICANT, "Error loading bundle",
e);

View file

@ -28,12 +28,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.procedures.Bundle;
import com.raytheon.viz.ui.actions.LoadSerializedXml;
import com.raytheon.viz.ui.BundleLoader;
import com.raytheon.viz.ui.editor.AbstractEditor;
/**
@ -54,8 +50,6 @@ import com.raytheon.viz.ui.editor.AbstractEditor;
*/
public class ProcedureLoadJob {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ProcedureLoadJob.class);
private static final ProcedureLoadJob instance = new ProcedureLoadJob();
@ -79,12 +73,7 @@ public class ProcedureLoadJob {
AbstractEditor editor = entry.getKey();
Bundle b = entry.getValue();
try {
LoadSerializedXml.loadTo(editor, b);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error loading bundle", e);
}
new BundleLoader(editor, b).run();
}
}

View file

@ -63,10 +63,10 @@ import com.raytheon.uf.viz.d2d.core.legend.D2DLegendResource.LegendMode;
import com.raytheon.uf.viz.d2d.core.map.MapScales;
import com.raytheon.uf.viz.d2d.core.map.MapScales.MapScale;
import com.raytheon.uf.viz.d2d.core.map.MapScales.PartId;
import com.raytheon.viz.ui.BundleLoader;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.HistoryList;
import com.raytheon.viz.ui.UiUtil;
import com.raytheon.viz.ui.actions.LoadSerializedXml;
import com.raytheon.viz.ui.color.BackgroundColor;
import com.raytheon.viz.ui.color.IBackgroundColorChangedListener;
import com.raytheon.viz.ui.editor.AbstractEditor;
@ -207,12 +207,7 @@ public class SideView extends ViewPart implements IMultiPaneEditor,
}
if (bundleToLoad != null) {
try {
LoadSerializedXml.loadTo(this, bundleToLoad);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error loading bundle view", e);
}
new BundleLoader(this, bundleToLoad).run();
}
}

View file

@ -100,6 +100,8 @@ import com.raytheon.viz.ui.presenter.components.WidgetConf;
* Jan 02, 2013 1441 djohnson Access GroupDefinitionManager in a static fashion.
* Jan 04, 2012 1420 mpduff Add Latency to PriorityComp.
* Jan 11, 2013 1453 djohnson Sets cycle times on construction.
* Jan 14, 2013 1286 djohnson Check that message to display is not null or empty, and
* only send notification of subscription creation on OK status.
* </pre>
*
* @author mpduff
@ -557,17 +559,21 @@ public class CreateSubscriptionDlgPresenter {
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
subscriptionNotificationService
.sendCreatedSubscriptionNotification(
subscription, username);
final IStatus status = event.getResult();
if (status.getMessage() != null) {
final boolean subscriptionCreated = status.isOK();
if (subscriptionCreated) {
sendSubscriptionNotification(subscription,
username);
}
if (!Strings.isNullOrEmpty(status.getMessage())) {
guiThreadTaskExecutor.runAsync(new Runnable() {
@Override
public void run() {
if (!view.isDisposed()) {
if (status.isOK()) {
if (subscriptionCreated) {
view.displayPopup(
CREATED_TITLE,
status.getMessage());

View file

@ -19,8 +19,12 @@
**/
package com.raytheon.uf.viz.datadelivery.subscription.xml;
import java.util.Collections;
import java.util.Map;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.google.common.collect.Maps;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
@ -35,7 +39,8 @@ import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 7, 2013 1420 mpduff Initial creation.
* Jan 07, 2013 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Add static versions of the conversion methods.
*
* </pre>
*
@ -44,32 +49,61 @@ import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
*/
public class OperatorAdapter extends XmlAdapter<String, Operator<?>> {
private static final Map<String, Operator<?>> OPERATOR_MAP;
static {
Map<String, Operator<?>> map = Maps.newHashMap();
for (Operator<?> operator : NameOperationItems.values()) {
map.put(toString(operator), operator);
}
for (Operator<?> operator : OperatorTypes.values()) {
map.put(toString(operator), operator);
}
for (Operator<?> operator : TypeOperationItems.values()) {
map.put(toString(operator), operator);
}
OPERATOR_MAP = Collections.unmodifiableMap(map);
}
/**
*
* {@inheritDoc}
*/
@Override
public Operator<?> unmarshal(String v) throws Exception {
for (OperatorTypes ot : OperatorTypes.values()) {
if (ot.toString().equals(v)) {
return ot;
}
}
for (NameOperationItems noi : NameOperationItems.values()) {
if (noi.toString().equals(v)) {
return noi;
}
}
for (TypeOperationItems toi : TypeOperationItems.values()) {
if (toi.toString().equals(v)) {
return toi;
}
}
return null;
return fromString(v);
}
/**
*
* {@inheritDoc}
*/
@Override
public String marshal(Operator<?> v) throws Exception {
return v.toString();
return toString(v);
}
/**
* Retrieve an {@link Operator} from its {@link String} representation.
*
* @param asString
* the string representation
* @return
*/
public static Operator<?> fromString(String asString) {
return OPERATOR_MAP.get(asString);
}
/**
* Retrieve the {@link String} representation of an {@link Operator}
* instance.
*
* @param operator
* the operator
* @return the {@link String} representation
*/
public static String toString(Operator<?> operator) {
return operator.toString();
}
}

View file

@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
@ -44,6 +44,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19, 2012 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Correct string conversion of units and use {@link Operator}.
*
* </pre>
*
@ -68,7 +69,7 @@ public abstract class RuleXML {
/** Rule operator */
@XmlElement
protected String ruleOperator;
protected Operator ruleOperator;
/** Rule value */
@XmlElement
@ -121,7 +122,7 @@ public abstract class RuleXML {
*
* @return the ruleOperator
*/
public String getRuleOperator() {
public Operator getRuleOperator() {
return ruleOperator;
}
@ -131,7 +132,7 @@ public abstract class RuleXML {
* @param ruleOperator
* The operator value of the rule
*/
public void setRuleOperator(String ruleOperator) {
public void setRuleOperator(Operator ruleOperator) {
this.ruleOperator = ruleOperator;
}
@ -192,38 +193,29 @@ public abstract class RuleXML {
unit = getRuleUnit();
}
OperatorAdapter oa = new OperatorAdapter();
Operator oper = null;
try {
oper = oa.unmarshal(ruleOperator);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
return false;
}
// If Data Name
if (OpsNetFieldNames.NAME.toString().equals(ruleField)) {
String dsName = sub.getDataSetName();
return oper.evaluate(dsName, ruleValue);
return ruleOperator.evaluate(dsName, ruleValue);
}
// If Data Type
if (OpsNetFieldNames.TYPE.toString().equals(ruleField)) {
String dsType = sub.getDataSetType().toString();
return oper.evaluate(ruleValue, dsType);
return ruleOperator.evaluate(ruleValue, dsType);
}
// If Data Size
if (OpsNetFieldNames.SIZE.toString().equals(ruleField)) {
long dsSizeKb = sub.getDataSetSize(); // Size in KB
long ruleValueInt = Integer.parseInt(ruleValue);
DataSizeUnit dsUnit = DataSizeUnit.valueOf(unit);
DataSizeUnit dsUnit = DataSizeUnit.fromString(ruleUnit);
ruleValueInt = dsUnit.toKB(ruleValueInt);
return oper.evaluate(Long.valueOf(dsSizeKb),
return ruleOperator.evaluate(Long.valueOf(dsSizeKb),
Long.valueOf(ruleValueInt));
}
@ -231,7 +223,7 @@ public abstract class RuleXML {
if (OpsNetFieldNames.FREQUENCY.toString().equals(ruleField)) {
// Calculate frequency
int ruleValueInt = Integer.parseInt(this.ruleValue);
if (unit.equalsIgnoreCase("Mins")) {
if (FreqUnitOptions.MIN.getOperation().equalsIgnoreCase(unit)) {
ruleValueInt /= 60;
}
int freq = 0;
@ -246,7 +238,8 @@ public abstract class RuleXML {
freq = val - tmp;
}
if (oper.evaluate(Long.valueOf(freq), Long.valueOf(ruleValueInt))) {
if (ruleOperator.evaluate(Long.valueOf(freq),
Long.valueOf(ruleValueInt))) {
return true;
}
}

View file

@ -38,6 +38,7 @@ import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.datadelivery.subscription.xml.LatencyRuleXML;
import com.raytheon.uf.viz.datadelivery.subscription.xml.OperatorAdapter;
import com.raytheon.uf.viz.datadelivery.subscription.xml.PriorityRuleXML;
import com.raytheon.uf.viz.datadelivery.subscription.xml.RuleXML;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
@ -65,6 +66,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Dec 18, 2012 1417 bgonzale Changed value initialization in handleSave().
* Jan 04, 2013 1420 mpduff Remove code to apply rules changes to existing subscription,
* rules are only for future subscriptions.
* Jan 14, 2013 1286 djohnson Rule operators are now used as objects.
*
* </pre>
*
@ -528,8 +530,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
updateSelectionFields(field);
String operator = ruleXml.getRuleOperator();
operationCombo.select(operationCombo.indexOf(operator));
operationCombo.select(operationCombo.indexOf(OperatorAdapter
.toString(ruleXml.getRuleOperator())));
String value = ruleXml.getRuleValue();
if (!value.isEmpty()) {
@ -646,8 +648,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
boolean valid = false;
String fieldName = fieldCombo.getItem(fieldCombo.getSelectionIndex());
String operator = operationCombo.getItem(operationCombo
.getSelectionIndex());
Operator operator = OperatorAdapter.fromString(operationCombo
.getItem(operationCombo.getSelectionIndex()));
if (create) {
valid = DataDeliveryGUIUtils.hasText(ruleNameText);

View file

@ -19,6 +19,10 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.viz.datadelivery.subscription.xml.OperatorAdapter;
/**
* Operator interface.
*
@ -28,14 +32,15 @@ package com.raytheon.uf.viz.datadelivery.system;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 7, 2013 mpduff Initial creation
* Jan 07, 2013 mpduff Initial creation
* Jan 14, 2013 djohnson Specify JAXB adapter on the interface.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
@XmlJavaTypeAdapter(value = OperatorAdapter.class)
public interface Operator<T> {
/**
* Evaluate whether the operator would return true when comparing operandOne

View file

@ -52,6 +52,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Sep 17, 2012 730 jpiatt Initial creation.
* Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
* Jan 04, 2012 1420 mpduff Add delete rule function.
* Jan 14, 2013 1286 djohnson Rule list is single item selectable.
*
* </pre>
*
@ -134,7 +135,7 @@ public class SystemLatencyTab {
gd.heightHint = 200;
latencyList = new List(latencyComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL);
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
latencyList.setLayoutData(gd);
latencyList.addSelectionListener(new SelectionAdapter() {
@Override

View file

@ -60,6 +60,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Nov 20, 2012 1286 djohnson Add showYesNoMessage.
* Dec 20, 2012 1413 bgonzale Added PendingSubColumnNames.valueOfColumnName(String).
* Jan 10, 2013 1420 mdpuff Added getMaxLatency().
* Jan 14, 2013 1286 djohnson Fix IndexOutOfBounds exception from getMaxLatency.
* </pre>
*
* @author mpduff
@ -554,9 +555,11 @@ public class DataDeliveryUtils {
Collections.sort(cycles);
int max = TimeUtil.HOURS_PER_DAY * TimeUtil.MINUTES_PER_HOUR;
for (int i = 0; i < cycles.size(); i++) {
if (i + 1 <= cycles.size()) {
int tempMax = cycles.get(i + 1) - cycles.get(i);
final int size = cycles.size();
for (int i = 0; i < size; i++) {
final int nextIndex = i + 1;
if (nextIndex < size) {
int tempMax = cycles.get(nextIndex) - cycles.get(i);
if (tempMax > max) {
max = tempMax;
}

View file

@ -1,5 +1,9 @@
package com.raytheon.uf.viz.datadelivery.utils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlType;
@ -14,6 +18,7 @@ import javax.xml.bind.annotation.XmlType;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 08, 2013 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Add lookup map via string version.
*
* </pre>
*
@ -201,4 +206,23 @@ public enum DataSizeUnit {
* @return converted value
*/
public abstract long convert(long l, DataSizeUnit ds);
private static final Map<String, DataSizeUnit> LOOKUP_MAP;
static {
Map<String, DataSizeUnit> map = new HashMap<String, DataSizeUnit>();
for (DataSizeUnit unit : DataSizeUnit.values()) {
map.put(unit.getUnit(), unit);
}
LOOKUP_MAP = Collections.unmodifiableMap(map);
}
/**
* Retrieve the {@link DataSizeUnit} for its string representation.
*
* @param asString
* @return
*/
public static DataSizeUnit fromString(String asString) {
return LOOKUP_MAP.get(asString);
}
}

View file

@ -54,7 +54,7 @@ import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability;
import com.raytheon.uf.viz.npp.crimss.CrimssNSharpResourceData;
import com.raytheon.viz.ui.MenuLoader;
import com.raytheon.viz.ui.BundleProductLoader;
import com.raytheon.viz.ui.UiUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
import com.raytheon.viz.ui.input.EditableManager;
@ -218,7 +218,7 @@ public class CrimssMapResource extends
display.cloneDisplay());
Bundle b = new Bundle();
b.setDisplays(new AbstractRenderableDisplay[] { display });
Job j = new MenuLoader(b, editor);
Job j = new BundleProductLoader(editor, b);
j.schedule();
}

View file

@ -50,7 +50,7 @@ import com.raytheon.uf.viz.core.rsc.ResourceProperties;
import com.raytheon.uf.viz.core.rsc.ResourceType;
import com.raytheon.uf.viz.productbrowser.ProductBrowserPreference.PreferenceType;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.MenuLoader;
import com.raytheon.viz.ui.BundleProductLoader;
import com.raytheon.viz.ui.VizWorkbenchManager;
import com.raytheon.viz.ui.editor.AbstractEditor;
import com.raytheon.viz.ui.perspectives.AbstractVizPerspectiveManager;
@ -216,8 +216,7 @@ public abstract class AbstractRequestableProductBrowserDataDefinition<T extends
display.getDescriptor().getResourceList().add(pair);
Bundle b = new Bundle();
b.setDisplays(new AbstractRenderableDisplay[] { display });
new MenuLoader(b, (AbstractEditor) EditorUtil.getActiveEditor())
.schedule();
new BundleProductLoader(EditorUtil.getActiveVizContainer(), b).schedule();
}
/**

View file

@ -56,8 +56,11 @@ import com.raytheon.uf.viz.core.procedures.BundleUtil.BundleDataItem;
import com.raytheon.uf.viz.core.rsc.URICatalog;
import com.raytheon.uf.viz.core.rsc.URICatalog.IURIRefreshCallback;
import com.raytheon.uf.viz.ui.menus.xml.BundleMenuContribution;
import com.raytheon.viz.ui.MenuLoader;
import com.raytheon.viz.ui.actions.LoadSerializedXml;
import com.raytheon.viz.ui.BundleLoader;
import com.raytheon.viz.ui.BundleLoader.BundleInfoType;
import com.raytheon.viz.ui.BundleProductLoader;
import com.raytheon.viz.ui.UiUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
/**
* Provides an Eclipse menu contribution that loads a bundle, and is decorated
@ -345,15 +348,19 @@ public class BundleContributionItem extends ContributionItem {
private void loadBundle(Event event) {
try {
Bundle bundle = BundleLoader.getBundle(
this.menuContribution.xml.bundleFile, substitutions,
BundleInfoType.FILE_LOCATION);
AbstractEditor editor = UiUtil.createOrOpenEditor(
this.menuContribution.xml.editorType, bundle.getDisplays());
BundleLoader loader;
if (this.menuContribution.xml.fullBundleLoad == null
|| this.menuContribution.xml.fullBundleLoad == false) {
MenuLoader.loadProduct(this.menuContribution.xml.editorType,
this.menuContribution.xml.bundleFile, substitutions);
loader = new BundleProductLoader(editor, bundle);
} else {
LoadSerializedXml.loadTo(PathManagerFactory.getPathManager()
.getStaticFile(this.menuContribution.xml.bundleFile),
substitutions);
loader = new BundleLoader(editor, bundle);
}
loader.schedule();
if (this.menuContribution.xml.command != null) {
ICommandService service = (ICommandService) PlatformUI

View file

@ -0,0 +1,346 @@
package com.raytheon.viz.ui;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.IEditorPart;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.core.AbstractTimeMatcher;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.drawables.AbstractRenderableDisplay;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.globals.VizGlobalsManager;
import com.raytheon.uf.viz.core.procedures.Bundle;
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
/**
*
* Loads a bundle to a container. Replaces contents of bundle on the container
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 8, 2013 mschenke Initial creation
*
* </pre>
*
* @author mschenke
* @version 1.0
*/
public class BundleLoader extends Job {
protected static final IUFStatusHandler statusHandler = UFStatus
.getHandler(BundleLoader.class);
public static enum BundleInfoType {
FILE_LOCATION, XML
}
protected static class LoadItem {
public final IDisplayPane loadTo;
public final IRenderableDisplay loadFrom;
public LoadItem(IDisplayPane loadTo, IRenderableDisplay loadFrom) {
this.loadTo = loadTo;
this.loadFrom = loadFrom;
}
}
private class InstantiationTask implements Runnable {
private LoadItem loadItem;
private InstantiationTask(LoadItem loadItem) {
this.loadItem = loadItem;
}
@Override
public void run() {
IDisplayPane loadTo = loadItem.loadTo;
IRenderableDisplay loadFrom = loadItem.loadFrom;
if (loadTo.getDescriptor() != loadFrom.getDescriptor()) {
load(loadTo, loadFrom);
}
loadTo.getDescriptor().getResourceList()
.instantiateResources(loadTo.getDescriptor(), true);
}
}
protected IDisplayPaneContainer container;
private Bundle bundle;
public BundleLoader(IDisplayPaneContainer container, Bundle bundle) {
this("Bundle Loader", container, bundle);
}
protected BundleLoader(String name, IDisplayPaneContainer container,
Bundle bundle) {
super(name);
this.container = container;
this.bundle = bundle;
}
/**
* Runs the loading synchronously.
*/
public final void run() {
run(new NullProgressMonitor());
}
@Override
protected final IStatus run(IProgressMonitor monitor) {
long t0 = System.currentTimeMillis();
try {
loadBundleToContainer(container, bundle);
if (bundle.getLoopProperties() != null) {
container.setLoopProperties(bundle.getLoopProperties());
}
/** refresh the editor */
container.refresh();
if (container instanceof IEditorPart) {
/** update the history list */
HistoryList.getInstance().refreshLatestBundle(
HistoryList.prepareHistoryEntry(container));
}
if (container instanceof IEditorPart) {
VizApp.runAsync(new Runnable() {
@Override
public void run() {
VizGlobalsManager.getCurrentInstance().updateUI(
container);
}
});
}
} catch (VizException e) {
return new Status(IStatus.ERROR, UiPlugin.PLUGIN_ID,
"Error loading bundle", e);
}
long t2 = System.currentTimeMillis();
System.out.println("Total bundle retrieval: " + (t2 - t0));
return Status.OK_STATUS;
}
/**
* Loads a {@link Bundle} onto an {@link IDisplayPaneContainer}
*
* @param container
* @param bundle
* @throws VizException
*/
private final void loadBundleToContainer(IDisplayPaneContainer container,
Bundle bundle) throws VizException {
LoadItem[] items = getLoadItems(container, bundle);
int numItems = items.length;
if (numItems > 0) {
Thread[] threads = new Thread[numItems - 1];
for (int i = 0; i < numItems; ++i) {
Thread t = new Thread(new InstantiationTask(items[i]));
if (i == 0) {
IRenderableDisplay loadFrom = items[i].loadFrom;
IDisplayPane loadTo = items[i].loadTo;
AbstractTimeMatcher srcTimeMatcher = loadFrom
.getDescriptor().getTimeMatcher();
if (srcTimeMatcher != null) {
loadTo.getDescriptor().getTimeMatcher()
.copyFrom(srcTimeMatcher);
}
loadTo.getDescriptor().getTimeMatcher().resetMultiload();
t.run();
} else {
t.start();
threads[i - 1] = t;
}
}
for (Thread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
// Ignore
}
}
}
}
/**
* Gets the pairing of display->pane loading that should occur. Each item
* will have {@link #load(IDisplayPane, IRenderableDisplay)} called on it
*
* @param container
* @param bundle
* @return
* @throws VizException
*/
protected LoadItem[] getLoadItems(IDisplayPaneContainer container,
Bundle bundle) throws VizException {
IDisplayPane[] containerPanes = container.getDisplayPanes();
AbstractRenderableDisplay[] bundleDisplays = bundle.getDisplays();
if (containerPanes.length != bundleDisplays.length) {
boolean success = ensureOneToOne(container, bundle);
containerPanes = container.getDisplayPanes();
if (success) {
throw new VizException("Unable to load "
+ bundleDisplays.length
+ " displays onto container with "
+ containerPanes.length + " panes");
}
}
int numPanes = containerPanes.length;
LoadItem[] items = new LoadItem[numPanes];
List<AbstractRenderableDisplay> orderedDisplays = Arrays
.asList(bundleDisplays);
for (int i = 0; i < numPanes; ++i) {
IDescriptor desc = bundleDisplays[i].getDescriptor();
if (desc.getTimeMatcher() != null) {
orderedDisplays = desc.getTimeMatcher().getDisplayLoadOrder(
orderedDisplays);
for (AbstractRenderableDisplay d : orderedDisplays) {
d.getDescriptor().synchronizeTimeMatching(desc);
}
break;
}
}
if (orderedDisplays.size() != numPanes) {
throw new VizException(
"Error ordering bundle displays. Number of displays returned not same as passed in");
}
int j = 0;
for (AbstractRenderableDisplay display : orderedDisplays) {
for (int i = 0; i < numPanes; ++i) {
if (display == bundleDisplays[i]) {
items[j] = new LoadItem(containerPanes[i],
bundleDisplays[i]);
}
}
++j;
}
return items;
}
/**
* Ensures there is a one to one relationship for number of panes on
* container to number of displays in bundle
*
* @param container
* @param bundle
* @return true of mapping is 1-1, false otherwise
*/
protected boolean ensureOneToOne(IDisplayPaneContainer container,
Bundle bundle) {
IDisplayPane[] containerPanes = container.getDisplayPanes();
AbstractRenderableDisplay[] bundleDisplays = bundle.getDisplays();
// Attempt to match 1-1 pane to display
if (container instanceof IMultiPaneEditor) {
final IMultiPaneEditor mpe = (IMultiPaneEditor) container;
final int numPanes = containerPanes.length;
final int numDisplays = bundleDisplays.length;
final IDisplayPane[] cPanes = containerPanes;
final AbstractRenderableDisplay[] bDisplays = bundleDisplays;
VizApp.runSync(new Runnable() {
@Override
public void run() {
for (int i = numPanes; i < numDisplays; ++i) {
// This will hit if fewer panes than displays
mpe.addPane(bDisplays[i]);
}
for (int i = numDisplays; i < numPanes; ++i) {
// This will hit if fewer displays than panes
mpe.removePane(cPanes[i]);
}
}
});
}
containerPanes = container.getDisplayPanes();
return containerPanes.length == bundleDisplays.length;
}
/**
* Loads the renderable display onto the pane
*
* @param loadTo
* @param loadFrom
*/
protected void load(final IDisplayPane loadTo,
final IRenderableDisplay loadFrom) {
VizApp.runSync(new Runnable() {
@Override
public void run() {
loadTo.setRenderableDisplay(loadFrom);
}
});
}
/**
* Gets a bundle object from bundle text, text type is specified by
* {@link BundleInfoType} passed in
*
* @param bundleText
* @param variables
* @param type
* @return
* @throws VizException
*/
public static Bundle getBundle(String bundleText,
Map<String, String> variables, BundleInfoType type)
throws VizException {
/** Make sure bundle text is not null */
if (bundleText == null) {
throw new IllegalArgumentException("Bundle text cannot be null");
}
Bundle b = null;
/** Is the bundle location the bundle xml or a file with the xml? */
if (type == BundleInfoType.FILE_LOCATION) {
/** File with xml */
b = Bundle.unmarshalBundle(PathManagerFactory.getPathManager()
.getStaticFile(bundleText), variables);
} else {
/** bundleLocation variable contains the xml */
b = Bundle.unmarshalBundle(bundleText, variables);
}
return b;
}
/**
* Schedules a {@link BundleLoader} to run to load the bundle on the
* container
*
* @param container
* @param b
*/
public static void loadTo(IDisplayPaneContainer container, Bundle b) {
new BundleLoader(container, b).schedule();
}
}

View file

@ -0,0 +1,168 @@
package com.raytheon.viz.ui;
import java.util.ArrayList;
import java.util.List;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.drawables.AbstractRenderableDisplay;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.procedures.Bundle;
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.viz.core.ColorUtil;
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
/**
*
* Loads a bundle as a product to a container. This will add the resources from
* the bundle displays onto the container instead of replacing
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 8, 2013 mschenke Initial creation
*
* </pre>
*
* @author mschenke
* @version 1.0
*/
public class BundleProductLoader extends BundleLoader {
public BundleProductLoader(IDisplayPaneContainer container, Bundle bundle) {
super("Product Loader", container, bundle);
}
@Override
protected LoadItem[] getLoadItems(IDisplayPaneContainer container,
Bundle bundle) throws VizException {
IDisplayPane[] containerPanes = container.getDisplayPanes();
AbstractRenderableDisplay[] bundleDisplays = bundle.getDisplays();
int bundleSize = bundleDisplays.length;
int editorSize = containerPanes.length;
IDisplayPane[] loadTo;
IRenderableDisplay[] loadFrom;
IDisplayPane selected = null;
if (container instanceof IMultiPaneEditor) {
selected = ((IMultiPaneEditor) container)
.getSelectedPane(IMultiPaneEditor.LOAD_ACTION);
}
// Figure out what panes to load to
if (selected != null && bundleSize == 1) {
// Only load to selected pane
loadTo = new IDisplayPane[] { selected };
loadFrom = new IRenderableDisplay[] { bundleDisplays[0] };
} else if (bundleSize == 1 && editorSize >= 1) {
loadTo = new IDisplayPane[editorSize];
loadFrom = new IRenderableDisplay[editorSize];
for (int i = 0; i < editorSize; ++i) {
loadTo[i] = containerPanes[i];
loadFrom[i] = bundleDisplays[0].cloneDisplay();
}
} else {
// Load 1-1
if (editorSize < bundleSize) {
// If fewer container panes than bundle displays, attempt to
// ensure 1-1 by adding panes
ensureOneToOne(container, bundle);
containerPanes = container.getDisplayPanes();
editorSize = containerPanes.length;
}
// Load what is possible
int maxCanLoad = Math.min(editorSize, bundleSize);
loadTo = new IDisplayPane[maxCanLoad];
loadFrom = new IRenderableDisplay[maxCanLoad];
for (int i = 0; i < maxCanLoad; ++i) {
loadTo[i] = containerPanes[i];
loadFrom[i] = bundleDisplays[i];
}
}
LoadItem[] items = new LoadItem[loadTo.length];
for (int i = 0; i < items.length; ++i) {
items[i] = new LoadItem(loadTo[i], loadFrom[i]);
}
return items;
}
@Override
protected void load(IDisplayPane loadTo, IRenderableDisplay loadFrom) {
IDescriptor existingDescriptor = loadTo.getDescriptor();
IDescriptor fromDescriptor = loadFrom.getDescriptor();
/**
* Update the frame count based on what has been listed in the bundle if
* we don't have times already loaded
*/
FramesInfo info = existingDescriptor.getFramesInfo();
if (info.getFrameCount() == 0) {
existingDescriptor.setNumberOfFrames(fromDescriptor
.getNumberOfFrames());
}
// Pull out the resources to load
ResourceList rscs = loadFrom.getDescriptor().getResourceList();
List<ResourcePair> resourcesToLoad = new ArrayList<ResourcePair>();
for (ResourcePair rp : rscs) {
if (rp.getProperties().isSystemResource() == false) {
resourcesToLoad.add(rp);
}
}
rscs.clear();
/**
* For each resource pair in the bundle resources: Give a unique color
* for the legend if one isn't set, add to pane's descriptor's resource
* list
*/
for (ResourcePair rp : resourcesToLoad) {
AbstractResourceData ard = rp.getResourceData();
try {
ard.configure(rp.getLoadProperties(), existingDescriptor);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
boolean newRP = true;
if (existingDescriptor.getResourceList().contains(rp)) {
newRP = false;
}
if (newRP
&& (rp.getProperties().isSystemResource() == false && !rp
.getLoadProperties().getCapabilities()
.hasCapability(ColorableCapability.class))) {
rp.getLoadProperties()
.getCapabilities()
.getCapability(rp.getResourceData(),
ColorableCapability.class)
.setColor(
ColorUtil.getNewColor(
container.getDisplayPanes(),
existingDescriptor, rp));
}
if (newRP) {
existingDescriptor.getResourceList().add(rp);
}
}
}
}

View file

@ -256,7 +256,10 @@ public class HistoryList {
}
public static Bundle prepareHistoryEntry() {
IDisplayPaneContainer cont = EditorUtil.getActiveVizContainer();
return prepareHistoryEntry(EditorUtil.getActiveVizContainer());
}
public static Bundle prepareHistoryEntry(IDisplayPaneContainer cont) {
if (cont != null) {
Bundle b = new Bundle();
com.raytheon.uf.viz.core.IDisplayPane[] panes = cont

View file

@ -1,350 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.viz.ui;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.AbstractTimeMatcher;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
import com.raytheon.uf.viz.core.drawables.ResourcePair;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.globals.VizGlobalsManager;
import com.raytheon.uf.viz.core.procedures.Bundle;
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.viz.core.ColorUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 2, 2009 chammack Initial creation
* Apr 7, 2009 2215 jsanchez Updated the scaleFile.
* June 25, 2010 1691 bkowal The frame count for the created /
* discovered editor will now be
* updated to match the frame
* count that was specified in the bundle.
*
* </pre>
*
* @author chammack
* @version 1.0
*/
public class MenuLoader extends Job {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(MenuLoader.class);
private Bundle bundle;
private AbstractEditor editor;
private class InstantiationThread extends Thread {
private IDisplayPane loadTo;
private IRenderableDisplay loadFrom;
public InstantiationThread(IDisplayPane loadTo,
IRenderableDisplay loadFrom) {
this.loadTo = loadTo;
this.loadFrom = loadFrom;
}
@Override
public void run() {
IDescriptor existingDescriptor = loadTo.getDescriptor();
/**
* Update the frame count based on what has been listed in the
* bundle if we don't have times already loaded
*/
FramesInfo info = existingDescriptor.getFramesInfo();
if (info.getFrameCount() == 0) {
existingDescriptor.setNumberOfFrames(loadFrom.getDescriptor()
.getNumberOfFrames());
}
// Pull out the resources to load
ResourceList rscs = loadFrom.getDescriptor().getResourceList();
List<ResourcePair> resourcesToLoad = new ArrayList<ResourcePair>();
for (ResourcePair rp : rscs) {
if (rp.getProperties().isSystemResource() == false) {
resourcesToLoad.add(rp);
}
}
rscs.clear();
/**
* For each resource pair in the bundle resources: Give a unique
* color for the legend if one isn't set, add to pane's descriptor's
* resource list
*/
for (ResourcePair rp : resourcesToLoad) {
AbstractResourceData ard = rp.getResourceData();
try {
ard.configure(rp.getLoadProperties(), existingDescriptor);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
boolean newRP = true;
if (existingDescriptor.getResourceList().contains(rp)) {
newRP = false;
}
if (newRP
&& (rp.getProperties().isSystemResource() == false && !rp
.getLoadProperties().getCapabilities()
.hasCapability(ColorableCapability.class))) {
rp.getLoadProperties()
.getCapabilities()
.getCapability(rp.getResourceData(),
ColorableCapability.class)
.setColor(
ColorUtil.getNewColor(
editor.getDisplayPanes(),
existingDescriptor, rp));
}
if (newRP) {
existingDescriptor.getResourceList().add(rp);
}
}
existingDescriptor.getResourceList().instantiateResources(
existingDescriptor, true);
}
}
public static enum BundleInfoType {
FILE_LOCATION, XML
}
public MenuLoader(Bundle b, AbstractEditor editor) {
super("Request EDEX Product");
this.bundle = b;
this.editor = editor;
}
public static void loadProduct(final String editorType,
final String bundleLocation, final Map<String, String> variables)
throws VizException {
loadProduct(editorType, bundleLocation, variables,
BundleInfoType.FILE_LOCATION);
}
public static void loadProduct(String editorType, String bundleLocation,
Map<String, String> variables, BundleInfoType type)
throws VizException {
Bundle b = null;
/** Make sure bundle location is not null */
if (bundleLocation == null) {
throw new VizException("bundleLocation was null");
}
/** Is the bundle location the bundle xml or a file with the xml? */
if (type.equals(BundleInfoType.FILE_LOCATION)) {
/** File with xml */
b = Bundle.unmarshalBundle(PathManagerFactory.getPathManager()
.getStaticFile(bundleLocation), variables);
} else {
/** bundleLocation variable contains the xml */
b = Bundle.unmarshalBundle(bundleLocation, null);
}
/** Load the editor from the bundle */
AbstractEditor editor = null;
editor = UiUtil.createOrOpenEditor(editorType, b.getDisplays());
/** Error loading the editor */
if (editor == null) {
throw new VizException("unable to get editor: " + editorType);
}
/**
* If the descriptor in the bundle did not get set as the descriptor in
* the editor, we need to go through and add the resources in the
* bundle's IDisplayPane's descriptor to the editor's IDisplayPane's
* descriptor, which is done in the job
*/
if (editor.getDisplayPanes()[0].getDescriptor() != b.getDisplays()[0]
.getDescriptor()) {
Job j = new MenuLoader(b, editor);
j.schedule();
} else {
/**
* The editor and bundle have the same descriptors meaning the
* editor was opened from the bundle so we need to instantiate the
* resources on them only (this needs to be done outside the job bc
* paint will be called immediately after this and the resources may
* not have been instantiated yet.
*
* TODO: There may be a way to create a list of resources from the
* bundle and in this statement just remove the resources from the
* editor then re add them in the job. so this doesn't hang on
* construction of the resource
*/
for (IDisplayPane pane : editor.getDisplayPanes()) {
pane.getDescriptor().getResourceList()
.instantiateResources(pane.getDescriptor(), true);
}
HistoryList.getInstance().refreshLatestBundle();
}
}
@Override
protected IStatus run(IProgressMonitor monitor) {
long t0 = System.currentTimeMillis();
try {
/** extracted to method when doing a refactor, not really needed */
loadExisting();
/** refresh the editor */
editor.refresh();
/** update the history list */
HistoryList.getInstance().refreshLatestBundle();
} catch (VizException e) {
return new Status(IStatus.ERROR, UiPlugin.PLUGIN_ID,
"Error loading bundle", e);
}
long t2 = System.currentTimeMillis();
System.out.println("Total bundle retrieval: " + (t2 - t0));
return Status.OK_STATUS;
}
private void loadExisting() throws VizException {
IDisplayPane selected = null;
if (editor instanceof IMultiPaneEditor) {
selected = ((IMultiPaneEditor) editor)
.getSelectedPane(IMultiPaneEditor.LOAD_ACTION);
}
int bundleSize = bundle.getDisplays().length;
int editorSize = editor.getDisplayPanes().length;
List<IDisplayPane> loadToPanes = new ArrayList<IDisplayPane>();
List<IRenderableDisplay> loadFromBundle = new ArrayList<IRenderableDisplay>();
List<Thread> executionThreads = new ArrayList<Thread>();
// Figure out what panes to load to
if (selected != null && bundleSize == 1) {
loadToPanes.add(selected);
loadFromBundle.add(bundle.getDisplays()[0]);
} else if (selected == null && bundleSize == 1) {
// load to all panes the single bundle display
for (IDisplayPane pane : editor.getDisplayPanes()) {
loadToPanes.add(pane);
loadFromBundle.add(bundle.getDisplays()[0].cloneDisplay());
}
} else {
int max = Math.max(bundleSize, editorSize);
for (int i = 0; i < max; ++i) {
if (editorSize > i) {
loadToPanes.add(editor.getDisplayPanes()[i]);
} else {
loadToPanes.add(null);
}
if (bundleSize > i) {
loadFromBundle.add(bundle.getDisplays()[i]);
} else {
loadFromBundle.add(null);
}
}
}
for (int i = 0; i < loadToPanes.size(); ++i) {
IDisplayPane loadTo = loadToPanes.get(i);
final IRenderableDisplay loadFrom = loadFromBundle.get(i);
if (i == 0) {
AbstractTimeMatcher srcTimeMatcher = loadFrom.getDescriptor()
.getTimeMatcher();
if (srcTimeMatcher != null) {
loadTo.getDescriptor().getTimeMatcher()
.copyFrom(srcTimeMatcher);
}
loadTo.getDescriptor().getTimeMatcher().resetMultiload();
new InstantiationThread(loadTo, loadFrom).run();
continue;
}
if (loadFrom == null) {
continue;
} else if (loadTo == null) {
if (editor instanceof IMultiPaneEditor) {
VizApp.runSync(new Runnable() {
@Override
public void run() {
((IMultiPaneEditor) (editor)).addPane(loadFrom);
}
});
}
continue;
}
Thread t = new InstantiationThread(loadTo, loadFrom);
t.start();
executionThreads.add(t);
}
for (Thread t : executionThreads) {
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
VizApp.runAsync(new Runnable() {
@Override
public void run() {
VizGlobalsManager.getCurrentInstance().updateUI(editor);
}
});
}
}

View file

@ -20,9 +20,6 @@
package com.raytheon.viz.ui.actions;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@ -46,21 +43,16 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.DescriptorMap;
import com.raytheon.uf.viz.core.IDisplayPane;
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.drawables.AbstractRenderableDisplay;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.drawables.IRenderableDisplay;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.globals.VizGlobalsManager;
import com.raytheon.uf.viz.core.procedures.Bundle;
import com.raytheon.uf.viz.core.procedures.Procedure;
import com.raytheon.uf.viz.core.rsc.ResourceList;
import com.raytheon.viz.ui.BundleLoader;
import com.raytheon.viz.ui.UiUtil;
import com.raytheon.viz.ui.VizWorkbenchManager;
import com.raytheon.viz.ui.editor.AbstractEditor;
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
/**
* Handles loading of bundles or procedures
@ -133,11 +125,10 @@ public class LoadSerializedXml extends AbstractHandler {
IDescriptor bundleDescriptor = renderableDisplay.getDescriptor();
String bundleEditorId = DescriptorMap.getEditorId(bundleDescriptor
.getClass().getName());
synchronizeDisplays(bundle);
AbstractEditor editor = UiUtil.createOrOpenEditor(bundleEditorId,
bundle.getDisplays());
loadTo(editor, bundle);
BundleLoader.loadTo(editor, bundle);
}
public static void loadProcedureToScreen(Procedure procedure,
@ -183,7 +174,6 @@ public class LoadSerializedXml extends AbstractHandler {
for (Bundle b : bundles) {
// If an editor is specified, or no view part is specified,
// assume an editor part
synchronizeDisplays(b);
if (b.getView() == null) {
String editorName = b.getEditor();
AbstractEditor openedEditor = UiUtil.createEditor(editorName,
@ -202,33 +192,22 @@ public class LoadSerializedXml extends AbstractHandler {
}
}
loadTo(openedEditor, b);
BundleLoader.loadTo(openedEditor, b);
} else {
// There is a view part specified
IViewPart part = UiUtil.findView(windowToLoadTo, b.getView(),
false);
if (part != null && part instanceof IDisplayPaneContainer) {
loadTo((IDisplayPaneContainer) part, b);
BundleLoader.loadTo((IDisplayPaneContainer) part, b);
}
}
}
}
private static void synchronizeDisplays(Bundle b) {
IDescriptor firstDesc = null;
for (AbstractRenderableDisplay d : b.getDisplays()) {
if (firstDesc == null) {
firstDesc = d.getDescriptor();
} else {
d.getDescriptor().synchronizeTimeMatching(firstDesc);
}
}
}
/**
* Load a bundle to a container
* Use {@link BundleLoader} instead
*
* @param editor
* the container to load to
@ -236,119 +215,10 @@ public class LoadSerializedXml extends AbstractHandler {
* the bundle
* @throws VizException
*/
public static void loadTo(final IDisplayPaneContainer container,
final Bundle b) throws VizException {
final int containerSize = container.getDisplayPanes().length;
final boolean multiEditor = container instanceof IMultiPaneEditor;
if (multiEditor) {
if (container.getDisplayPanes().length > b.getDisplays().length) {
VizApp.runSync(new Runnable() {
@Override
public void run() {
while (container.getDisplayPanes().length > b
.getDisplays().length) {
((IMultiPaneEditor) container).removePane(container
.getDisplayPanes()[container
.getDisplayPanes().length - 1]);
}
}
});
}
}
List<AbstractRenderableDisplay> orderedDisplays = Arrays.asList(b
.getDisplays());
IDescriptor firstDesc = orderedDisplays.get(0).getDescriptor();
if (firstDesc != null && firstDesc.getTimeMatcher() != null) {
orderedDisplays = firstDesc.getTimeMatcher().getDisplayLoadOrder(
orderedDisplays);
}
for (AbstractRenderableDisplay d : orderedDisplays) {
d.getDescriptor().synchronizeTimeMatching(firstDesc);
ResourceList rl = d.getDescriptor().getResourceList();
rl.instantiateResources(d.getDescriptor(), true);
}
final VizException[] errors = new VizException[1];
VizApp.runSync(new Runnable() {
@Override
public void run() {
int i = 0;
for (AbstractRenderableDisplay d : b.getDisplays()) {
if (i >= containerSize && multiEditor) {
((IMultiPaneEditor) container).addPane(d);
} else if (i >= containerSize) {
errors[0] = new VizException(
"Unable to add panes to non IMultiPaneEditor");
return;
} else {
IRenderableDisplay oldDisplay = container
.getDisplayPanes()[i].getRenderableDisplay();
if (oldDisplay != null && oldDisplay != d) {
oldDisplay.dispose();
}
container.getDisplayPanes()[i].setRenderableDisplay(d);
container.getDisplayPanes()[i].resize();
container.getDisplayPanes()[i].refresh();
}
i++;
}
if (b.getLoopProperties() != null) {
container.setLoopProperties(b.getLoopProperties());
}
// if loading to an editor, update the globals
if (container instanceof IEditorPart) {
VizGlobalsManager.getCurrentInstance().updateUI(container);
}
}
});
if (errors[0] != null) {
throw errors[0];
}
}
/**
* Load a bundle from a file into a container
*
* @param editor
* the container to load to
* @param f
* the file containing the bundle
* @param descriptor
* Optional: A descriptor that should be used for time matching
* @throws VizException
*/
public static void loadTo(File f, Map<String, String> variables)
@Deprecated
public static void loadTo(final IDisplayPaneContainer container, Bundle b)
throws VizException {
Bundle b = Bundle.unmarshalBundle(f, variables);
IRenderableDisplay renderableDisplay = b.getDisplays()[0];
IDescriptor bundleDescriptor = renderableDisplay.getDescriptor();
String bundleEditorId = DescriptorMap.getEditorId(bundleDescriptor
.getClass().getName());
AbstractEditor editor = UiUtil.createOrOpenEditor(bundleEditorId,
b.getDisplays());
loadTo(editor, b);
new BundleLoader(container, b).run();
}
public static void loadTo(IDisplayPane pane, File f,
Map<String, String> variables) throws VizException {
Bundle b = Bundle.unmarshalBundle(f, variables);
for (AbstractRenderableDisplay d : b.getDisplays()) {
ResourceList rl = d.getDescriptor().getResourceList();
rl.instantiateResources(d.getDescriptor(), true);
pane.setRenderableDisplay(d);
pane.resize();
pane.refresh();
}
}
}

View file

@ -88,7 +88,7 @@ import com.raytheon.viz.core.slice.request.VerticalPointRequest.TimeDirection;
import com.raytheon.viz.skewt.SkewtDisplay;
import com.raytheon.viz.skewt.rscdata.SkewTResourceData;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.MenuLoader;
import com.raytheon.viz.ui.BundleProductLoader;
import com.raytheon.viz.ui.UiUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
import com.raytheon.viz.ui.editor.IMultiPaneEditor;
@ -1078,7 +1078,7 @@ public class ProductTableComp extends Composite {
Bundle b = new Bundle();
b.setDisplays(new AbstractRenderableDisplay[] { display });
Job j = new MenuLoader(b, editor);
Job j = new BundleProductLoader(editor, b);
j.schedule();
}
}

View file

@ -3,11 +3,8 @@ package com.raytheon.uf.common.datadelivery.registry;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@ -22,6 +19,8 @@ import com.raytheon.uf.common.registry.annotations.SlotAttribute;
import com.raytheon.uf.common.serialization.ISerializableObject;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
*
@ -64,6 +63,7 @@ public class Provider implements ISerializableObject {
* ------------ ---------- ----------- --------------------------
* Feb 16, 2012 dhladky Initial creation
* Nov 19, 2012 1166 djohnson Clean up JAXB representation of registry objects.
* Jan 14, 2013 1286 djohnson Extracted {@link IDuration}.
*
* </pre>
*
@ -167,16 +167,9 @@ public class Provider implements ISerializableObject {
@SlotAttribute
private ServiceType serviceType;
// NOTE: The @XmlElement is on the getter because JAXB must call the setter
// for this value
@XmlElement
@DynamicSerializeElement
private String postedFileDelay;
@Transient
private int postedFileDelayValue = 0;
@Transient
private TimeUnit postedFileDelayUnits = TimeUnit.HOURS;
private IDuration postedFileDelay = Durations.ZERO;
/**
* The amount of time that should elapse between HTTP requests while
@ -225,29 +218,10 @@ public class Provider implements ISerializableObject {
/**
* @return the postedFileDelay
*/
@XmlElement(name = "postedFileDelay")
public String getPostedFileDelay() {
public IDuration getPostedFileDelay() {
return postedFileDelay;
}
/**
* Return the {@link TimeUnit} for the posted file delay.
*
* @return the {@link TimeUnit}
*/
public TimeUnit getPostedFileDelayUnits() {
return postedFileDelayUnits;
}
/**
* Return the value of the posted file delay.
*
* @return the value
*/
public int getPostedFileDelayValue() {
return postedFileDelayValue;
}
public List<Projection> getProjection() {
return projection;
}
@ -321,25 +295,10 @@ public class Provider implements ISerializableObject {
* if the string value cannot be parsed into a value and/or
* units
*/
public void setPostedFileDelay(String postedFileDelay) {
public void setPostedFileDelay(IDuration postedFileDelay) {
checkNotNull(postedFileDelay, "postedFileDelay cannot be null!");
this.postedFileDelay = postedFileDelay;
Matcher matcher = POSTED_FILE_DELAY_PATTERN.matcher(postedFileDelay);
if (matcher.matches()) {
postedFileDelayValue = Integer.parseInt(matcher.group(1));
String units = matcher.group(2);
postedFileDelayUnits = TimeUnit.valueOf(units);
if (postedFileDelayUnits == null) {
throw new IllegalArgumentException(units
+ " cannot be parsed into a valid units instance!");
}
} else {
throw new IllegalArgumentException(postedFileDelay
+ " cannot be parsed into a valid value and units!");
}
}
public void setProjection(List<Projection> projection) {

View file

@ -18,5 +18,7 @@ Import-Package: javax.persistence,
Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization
Export-Package: com.raytheon.uf.common.time,
com.raytheon.uf.common.time.adapter,
com.raytheon.uf.common.time.domain,
com.raytheon.uf.common.time.domain.api,
com.raytheon.uf.common.time.msgs,
com.raytheon.uf.common.time.util

View file

@ -0,0 +1,165 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* Implementation of {@link IDuration}. Intentionally package-private as it is
* an implementation detail, and not part of the public API. All access should
* be constrained through {@link Durations}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 10, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = IDurationTypeAdapter.class)
@DynamicSerializeTypeAdapter(factory = IDurationTypeAdapter.class)
class Duration implements IDuration {
private final long valueAsNanoseconds;
/**
* Constructor.
*
* @param value
* the unit value
* @param unit
* the unit
*/
Duration(long value, TimeUnit unit) {
this.valueAsNanoseconds = unit.toNanos(value);
}
/**
* {@inheritDoc}
*/
@Override
public long getNanos() {
return convert(TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getMicros() {
return convert(TimeUnit.MICROSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getMillis() {
return convert(TimeUnit.MILLISECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getSeconds() {
return convert(TimeUnit.SECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public long getMinutes() {
return convert(TimeUnit.MINUTES);
}
/**
* {@inheritDoc}
*/
@Override
public long getHours() {
return convert(TimeUnit.HOURS);
}
/**
* {@inheritDoc}
*/
@Override
public long getDays() {
return convert(TimeUnit.DAYS);
}
private long convert(TimeUnit targetUnit) {
return targetUnit.convert(valueAsNanoseconds, TimeUnit.NANOSECONDS);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof IDuration) {
IDuration other = (IDuration) obj;
return other.getNanos() == this.getNanos();
}
return super.equals(obj);
}
@Override
public int hashCode() {
return (int) this.getNanos();
}
/**
* {@inheritDoc}
*/
@Override
public Duration plus(IDuration anotherDuration) {
return new Duration(getNanos() + anotherDuration.getNanos(),
TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public Duration minus(IDuration anotherDuration) {
return new Duration(getNanos() - anotherDuration.getNanos(),
TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return Durations.toString(this);
}
}

View file

@ -0,0 +1,140 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Retrieve {@link IDuration}s.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public final class Durations {
private static final Pattern DURATION_PATTERN = Pattern
.compile("\\s*(\\d+)\\s+([^\\s]+)\\s*");
public static final IDuration ZERO = Durations
.of(0L, TimeUnit.MILLISECONDS);
/**
* Retrieve a {@link IDuration} of the specified value and unit.
*
* @param value
* @param unit
* @return the duration
*/
public static IDuration of(long value, TimeUnit unit) {
return new Duration(value, unit);
}
/**
* Retrieve the duration between two {@link TimePoint}s.
*
* @param start
* the starting time point
* @param end
* the ending time point
* @return the duration between the two points
*/
public static IDuration between(ITimePoint start, ITimePoint end) {
final long millis = end.asMilliseconds() - start.asMilliseconds();
return of(millis, TimeUnit.MILLISECONDS);
}
/**
* Parse a string representation of a {@link Duration}.
*
* @param asString
* the string representation of the duration
*
* @return the duration
* @throws IllegalArgumentException
* if the argument cannot be parsed into a duration
*/
public static IDuration fromString(String asString) {
final Matcher m = DURATION_PATTERN.matcher(asString);
if (m.matches()) {
return of(Long.parseLong(m.group(1)), TimeUnit.valueOf(m.group(2)));
}
throw new IllegalArgumentException("The argument [" + asString
+ "] does not match a duration!");
}
/**
* Convert the {@link IDuration} to a string representation. This method
* figures out the "optimal" unit to display the time in, e.g. 120 minutes
* would display as "2 HOURS", but 128 minutes will be displayed as "128
* MINUTES".
*
* @param duration
* the duration instance
* @return the string representation
*/
public static String toString(IDuration duration) {
TimeUnit timeUnitForDisplay = TimeUnit.DAYS;
final TimeUnit[] values = TimeUnit.values();
final long nanos = duration.getNanos();
for (int unitIdx = 1; unitIdx < values.length; unitIdx++) {
final TimeUnit timeUnitToTry = values[unitIdx];
// If we would lose precision, then use the time unit before this
// one
final long valueInNewTimeUnit = timeUnitToTry.convert(nanos,
TimeUnit.NANOSECONDS);
final boolean wouldLosePrecision = timeUnitToTry
.toNanos(valueInNewTimeUnit) != nanos;
if (wouldLosePrecision) {
timeUnitForDisplay = values[unitIdx - 1];
break;
}
}
// Now construct and return the pretty version of the String
final long convertedValue = timeUnitForDisplay.convert(nanos,
TimeUnit.NANOSECONDS);
return convertedValue + " " + timeUnitForDisplay.toString();
}
/**
* Disabled constructor.
*/
private Durations() {
}
}

View file

@ -0,0 +1,86 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.raytheon.uf.common.serialization.IDeserializationContext;
import com.raytheon.uf.common.serialization.ISerializationContext;
import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* {@link ISerializationTypeAdapter} for {@link IDuration} instances.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class IDurationTypeAdapter extends XmlAdapter<String, IDuration>
implements
ISerializationTypeAdapter<IDuration> {
/**
* {@inheritDoc}
*/
@Override
public void serialize(ISerializationContext serializer, IDuration object)
throws SerializationException {
serializer.writeI64(object.getNanos());
}
/**
* {@inheritDoc}
*/
@Override
public IDuration deserialize(IDeserializationContext deserializer)
throws SerializationException {
return Durations.of(deserializer.readI64(), TimeUnit.NANOSECONDS);
}
/**
* {@inheritDoc}
*/
@Override
public IDuration unmarshal(String v) throws Exception {
return Durations.fromString(v);
}
/**
* {@inheritDoc}
*/
@Override
public String marshal(IDuration v) throws Exception {
return Durations.toString(v);
}
}

View file

@ -0,0 +1,93 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.raytheon.uf.common.serialization.IDeserializationContext;
import com.raytheon.uf.common.serialization.ISerializationContext;
import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* {@link ISerializationTypeAdapter} for {@link ITimePoint} instances.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class ITimeIntervalTypeAdapter extends
XmlAdapter<TimeIntervalJaxbable, ITimeInterval> implements
ISerializationTypeAdapter<ITimeInterval> {
/**
* {@inheritDoc}
*/
@Override
public void serialize(ISerializationContext serializer, ITimeInterval object)
throws SerializationException {
serializer.writeObject(object.getStart());
serializer.writeObject(object.getEnd());
}
/**
* {@inheritDoc}
*/
@Override
public ITimeInterval deserialize(IDeserializationContext deserializer)
throws SerializationException {
ITimePoint start = (ITimePoint) deserializer.readObject();
ITimePoint end = (ITimePoint) deserializer.readObject();
return TimeIntervals.fromTimePoints(start, end);
}
/**
* {@inheritDoc}
*/
@Override
public ITimeInterval unmarshal(TimeIntervalJaxbable v)
throws Exception {
return TimeIntervals.fromTimePoints(TimePoints.fromDate(v.getStart()),
TimePoints.fromDate(v.getEnd()));
}
/**
* {@inheritDoc}
*/
@Override
public TimeIntervalJaxbable marshal(ITimeInterval v) throws Exception {
TimeIntervalJaxbable jaxbable = new TimeIntervalJaxbable();
jaxbable.setStart(v.getStart().asDate());
jaxbable.setEnd(v.getEnd().asDate());
return jaxbable;
}
}

View file

@ -0,0 +1,83 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.raytheon.uf.common.serialization.IDeserializationContext;
import com.raytheon.uf.common.serialization.ISerializationContext;
import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* {@link ISerializationTypeAdapter} for {@link ITimePoint} instances.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class ITimePointTypeAdapter extends XmlAdapter<Date, ITimePoint>
implements ISerializationTypeAdapter<ITimePoint> {
/**
* {@inheritDoc}
*/
@Override
public void serialize(ISerializationContext serializer, ITimePoint object)
throws SerializationException {
serializer.writeI64(object.asMilliseconds());
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint deserialize(IDeserializationContext deserializer)
throws SerializationException {
return TimePoints.fromMillis(deserializer.readI64());
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint unmarshal(Date v) throws Exception {
return TimePoints.fromDate(v);
}
/**
* {@inheritDoc}
*/
@Override
public Date marshal(ITimePoint v) throws Exception {
return v.asDate();
}
}

View file

@ -0,0 +1,136 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Implementation of {@link ITimeInterval}. Intentionally package-private as it
* is an implementation detail, and not part of the public API. All access
* should be constrained through {@link TimeIntervals}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimeIntervalTypeAdapter.class)
@DynamicSerializeTypeAdapter(factory = ITimeIntervalTypeAdapter.class)
class TimeInterval implements ITimeInterval {
private final ITimePoint intervalStart;
private final ITimePoint intervalEnd;
/**
* Constructor.
*
* @param intervalStart
* the start of the interval
* @param intervalEnd
* the end of the interval
*/
TimeInterval(ITimePoint intervalStart, ITimePoint intervalEnd) {
this.intervalStart = intervalStart;
this.intervalEnd = intervalEnd;
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint getStart() {
return intervalStart;
}
/**
* {@inheritDoc}
*/
@Override
public ITimePoint getEnd() {
return intervalEnd;
}
/**
* {@inheritDoc}
*/
@Override
public boolean containsTimePoint(ITimePoint timePoint) {
final boolean intervalStartSameOrBefore = intervalStart
.isBefore(timePoint) || intervalStart.isSame(timePoint);
final boolean intervalEndSameOrAfter = intervalEnd.isAfter(timePoint)
|| intervalEnd.isSame(timePoint);
return intervalStartSameOrBefore && intervalEndSameOrAfter;
}
/**
* {@inheritDoc}
*/
@Override
public IDuration getDuration() {
return Durations.between(intervalStart, intervalEnd);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof ITimeInterval) {
ITimeInterval other = (ITimeInterval) obj;
return this.getStart().equals(other.getStart())
&& this.getEnd().equals(other.getEnd());
}
return super.equals(obj);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return getStart().hashCode() + getEnd().hashCode();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("start [").append(getStart()).append("]");
sb.append(" end [").append(getEnd()).append("]");
sb.append(" duration [").append(getDuration()).append("]");
return sb.toString();
}
}

View file

@ -0,0 +1,91 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
/**
* Representation of a {@link ITimeInterval} for the purpose of JAXB. This class
* should only be used for converting to and from JAXB in
* {@link ITimeIntervalTypeAdapter}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(propOrder = { "start", "end" })
public class TimeIntervalJaxbable {
@XmlElement(required = true)
private Date start;
@XmlElement(required = true)
private Date end;
/**
* @return the start
*/
public Date getStart() {
return start;
}
/**
* @param start
* the start to set
*/
public void setStart(Date start) {
this.start = start;
}
/**
* @return the end
*/
public Date getEnd() {
return end;
}
/**
* @param end
* the end to set
*/
public void setEnd(Date end) {
this.end = end;
}
}

View file

@ -0,0 +1,69 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Utility class to work with {@link ITimeInterval}s
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public final class TimeIntervals {
/**
* Construct a {@link ITimeInterval} from two {@link ITimePoint}s.
*
* @param start
* the start of the time interval
* @param end
* the end of the time interval
* @return the interval
*/
public static ITimeInterval fromTimePoints(ITimePoint start, ITimePoint end) {
if (end.isBefore(start)) {
throw new IllegalArgumentException(
"The end time point cannot be before the start time point:\n[end = "
+ end + "] [start = " + start + "]");
}
return new TimeInterval(start, end);
}
/**
* No construction.
*/
private TimeIntervals() {
}
}

View file

@ -0,0 +1,148 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.time.util.TimeUtil;
/**
* Implementation of {@link ITimePoint}. Intentionally package-private as it is
* an implementation detail, and not part of the public API. All access should
* be constrained through {@link TimePoints}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimePointTypeAdapter.class)
@DynamicSerializeTypeAdapter(factory = ITimePointTypeAdapter.class)
class TimePoint implements ITimePoint {
private final long milliseconds;
/**
* Construct a {@link TimePoint} for the specified milliseconds.
*
* @param milliseconds
*/
TimePoint(long milliseconds) {
this.milliseconds = milliseconds;
}
/**
* Deep-copy another {@link ITimePoint}.
*
* @param toCopy
*/
TimePoint(ITimePoint toCopy) {
this(toCopy.asMilliseconds());
}
/**
* {@inheritDoc}
*/
@Override
public Date asDate() {
return new Date(milliseconds);
}
/**
* {@inheritDoc}
*/
@Override
public long asMilliseconds() {
return milliseconds;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAfter(ITimePoint anotherTimePoint) {
return this.asMilliseconds() > anotherTimePoint.asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isBefore(ITimePoint anotherTimePoint) {
return this.asMilliseconds() < anotherTimePoint.asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isSame(ITimePoint anotherPoint) {
return this.asMilliseconds() == anotherPoint.asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isWithin(ITimeInterval interval) {
return interval.containsTimePoint(this);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof ITimePoint) {
ITimePoint other = (ITimePoint) obj;
return this.isSame(other);
}
return super.equals(obj);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return (int) asMilliseconds();
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return TimeUtil.formatDate(asDate());
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import java.util.Date;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.time.util.TimeUtil;
/**
* Utility class to work with {@link ITimePoint}s.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public final class TimePoints {
/**
* Return the {@link ITimePoint} instance for the specified milliseconds.
*
* @return the milliseconds as an {@link ITimePoint}
*/
public static ITimePoint fromMillis(long milliseconds) {
return new TimePoint(milliseconds);
}
/**
* Return the {@link ITimePoint} instance for the specified {@link Date}.
*
* @return the date as an {@link ITimePoint}
*/
public static ITimePoint fromDate(Date date) {
return new TimePoint(date.getTime());
}
/**
* Return the {@link ITimePoint} instance of the current time.
*
* @return now, as an {@link ITimePoint}
*/
public static ITimePoint now() {
return fromDate(TimeUtil.newImmutableDate());
}
private TimePoints() {
}
}

View file

@ -0,0 +1,138 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain.api;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.datatype.Duration;
import com.raytheon.uf.common.time.domain.IDurationTypeAdapter;
/**
* Interface for a duration.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = IDurationTypeAdapter.class)
public interface IDuration {
/**
* Retrieve the number of nanoseconds represented by the duration.
* Conversions from finer to coarser granularities truncate, so lose
* precision. For example converting <tt>999</tt> milliseconds to seconds
* results in <tt>0</tt>.
*
* @return the number of nanoseconds, or 0 if the converted value is less
* than 1 of the new unit
*/
long getNanos();
/**
* Retrieve the number of microseconds represented by the duration.
* Conversions from finer to coarser granularities truncate, so lose
* precision. For example converting <tt>999</tt> milliseconds to seconds
* results in <tt>0</tt>.
*
* @return the number of microseconds, or 0 if the converted value is less
* than 1 of the new unit
*/
long getMicros();
/**
* Retrieve the number of milliseconds represented by the duration.
* Conversions from finer to coarser granularities truncate, so lose
* precision. For example converting <tt>999</tt> milliseconds to seconds
* results in <tt>0</tt>.
*
* @return the number of milliseconds, or 0 if the converted value is less
* than 1 of the new unit
*/
long getMillis();
/**
* Retrieve the number of seconds represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of seconds, or 0 if the converted value is less than 1
* of the new unit
*/
long getSeconds();
/**
* Retrieve the number of minutes represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of minutes, or 0 if the converted value is less than 1
* of the new unit
*/
long getMinutes();
/**
* Retrieve the number of hours represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of hours, or 0 if the converted value is less than 1
* of the new unit
*/
long getHours();
/**
* Retrieve the number of hours represented by the duration. Conversions
* from finer to coarser granularities truncate, so lose precision. For
* example converting <tt>999</tt> milliseconds to seconds results in
* <tt>0</tt>.
*
* @return the number of days, or 0 if the converted value is less than 1 of
* the new unit
*/
long getDays();
/**
* Add another {@link Duration} to this one.
*
* @param anotherDuration
* @return the duration of the sum
*/
IDuration plus(IDuration anotherDuration);
/**
* Subtract another {@link Duration} from this one.
*
* @param anotherDuration
* @return the duration of the difference
*/
IDuration minus(IDuration anotherDuration);
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain.api;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.time.domain.ITimeIntervalTypeAdapter;
/**
* Represents a specific interval in time.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimeIntervalTypeAdapter.class)
public interface ITimeInterval {
/**
* Return the start {@link ITimePoint} of the {@link ITimeInterval}.
*
* @return the time point the interval started
*/
ITimePoint getStart();
/**
* Return the end {@link ITimePoint} of the {@link ITimeInterval}.
*
* @return the time point the interval ended
*/
ITimePoint getEnd();
/**
* Check whether an {@link ITimePoint} falls within the
* {@link ITimeInterval}.
*
* @param timePoint
* the time point
* @return true if the interval contains the point
*/
boolean containsTimePoint(ITimePoint timePoint);
/**
* Retrieve the duration of the {@link ITimeInterval}.
*
* @return the duration
*/
IDuration getDuration();
}

View file

@ -0,0 +1,98 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain.api;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.time.domain.ITimePointTypeAdapter;
/**
* Represents an instance in time.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@XmlJavaTypeAdapter(value = ITimePointTypeAdapter.class)
public interface ITimePoint {
/**
* Return the {@link ITimePoint} as a {@link Date}.
*
* @return the {@link ITimePoint} as a {@link Date}
*/
Date asDate();
/**
* Return the {@link ITimePoint} as the milliseconds which would be returned
* by {@link Date}.
*
* @return the milliseconds
*/
long asMilliseconds();
/**
* Check whether this {@link ITimePoint} is before another one.
*
* @param anotherPoint
* the other {@link ITimePoint}
* @return true if this point in time is before the other one
*/
boolean isBefore(ITimePoint anotherPoint);
/**
* Check whether this {@link ITimePoint} is after another one.
*
* @param anotherPoint
* the other {@link ITimePoint}
* @return true if this point in time is after the other one
*/
boolean isAfter(ITimePoint anotherPoint);
/**
* Check whether this {@link ITimePoint} is the same as another one.
*
* @param anotherPoint
* the other {@link ITimePoint}
* @return true if this point in time is the same as the other one
*/
boolean isSame(ITimePoint anotherPoint);
/**
* Check whether this {@link ITimePoint} falls within the specified
* {@link ITimeInterval}.
*
* @param interval
* the {@link ITimeInterval}
* @return true if this point in time is within the time interval
*/
boolean isWithin(ITimeInterval interval);
}

View file

@ -1,5 +1,8 @@
package com.raytheon.uf.common.time.util;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
*
@ -13,19 +16,19 @@ package com.raytheon.uf.common.time.util;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 16, 2012 0743 djohnson Initial creation
* Jan 14, 2013 1286 djohnson Use time domain API.
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
// @NotThreadSafe
abstract class AbstractTimer implements ITimer {
private long start;
private ITimePoint start;
private long stop;
private ITimePoint stop;
private long elapsedTime;
private IDuration elapsedTime = Durations.ZERO;
/**
* {@inheritDoc}
@ -33,8 +36,8 @@ abstract class AbstractTimer implements ITimer {
@Override
public void start() {
if (isTimerStopped()) {
elapsedTime += (stop - start);
stop = 0;
elapsedTime = elapsedTime.plus(Durations.between(start, stop));
stop = null;
} else if (isTimerStarted()) {
throw new IllegalStateException(
"A timer that is running must be stopped before start() is called again!");
@ -62,8 +65,21 @@ abstract class AbstractTimer implements ITimer {
*/
@Override
public long getElapsedTime() {
long currentOrStopTime = (isTimerRunning()) ? getCurrentTime() : stop;
return (currentOrStopTime - start) + elapsedTime;
return getElapsed().getMillis();
}
/**
* {@inheritDoc}
*/
@Override
public IDuration getElapsed() {
ITimePoint currentOrStopTime = (isTimerRunning()) ? getCurrentTime()
: stop;
if (currentOrStopTime == null && start == null) {
return Durations.ZERO;
}
IDuration currentRun = Durations.between(start, currentOrStopTime);
return currentRun.plus(elapsedTime);
}
/**
@ -71,12 +87,12 @@ abstract class AbstractTimer implements ITimer {
*/
@Override
public void reset() {
start = 0;
stop = 0;
elapsedTime = 0;
start = null;
stop = null;
elapsedTime = Durations.ZERO;
}
protected abstract long getCurrentTime();
protected abstract ITimePoint getCurrentTime();
/**
* Check whether the timer is actively running.
@ -93,7 +109,7 @@ abstract class AbstractTimer implements ITimer {
* @return true if the timer was started
*/
private boolean isTimerStarted() {
return start > 0;
return start != null;
}
/**
@ -102,6 +118,6 @@ abstract class AbstractTimer implements ITimer {
* @return true if the timer is stopped
*/
private boolean isTimerStopped() {
return stop > 0;
return stop != null;
}
}

View file

@ -1,5 +1,7 @@
package com.raytheon.uf.common.time.util;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
*
* Defines a timer that can be started and stopped.
@ -11,6 +13,7 @@ package com.raytheon.uf.common.time.util;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 16, 2012 0743 djohnson Initial creation
* Jan 11, 2013 djohnson Use {@link IDuration}.
*
* </pre>
*
@ -43,6 +46,13 @@ public interface ITimer {
*/
long getElapsedTime();
/**
* Get the elapsed time
*
* @return the elapsed time
*/
IDuration getElapsed();
/**
* Reset the timer.
*/

View file

@ -28,6 +28,8 @@ import java.util.TimeZone;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.common.time.domain.TimePoints;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Utilities for time, some extracted from Util.
@ -63,9 +65,11 @@ public class TimeUtil {
*
*/
private static class NullClock extends AbstractTimer {
private static final ITimePoint CONSTANT_TIME = TimePoints
.fromMillis(1L);
@Override
protected long getCurrentTime() {
return 1;
protected ITimePoint getCurrentTime() {
return CONSTANT_TIME;
}
}

View file

@ -1,5 +1,8 @@
package com.raytheon.uf.common.time.util;
import com.raytheon.uf.common.time.domain.TimePoints;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
*
@ -27,7 +30,7 @@ class TimerImpl extends AbstractTimer {
* {@inheritDoc}
*/
@Override
protected long getCurrentTime() {
return TimeUtil.currentTimeMillis();
protected ITimePoint getCurrentTime() {
return TimePoints.fromMillis(TimeUtil.currentTimeMillis());
}
}

View file

@ -154,8 +154,15 @@ public abstract class Crawler {
File lockFileDir, String crawlType) {
FileChannel channel = null;
FileOutputStream fos = null;
// if lock file directories don't exist, create
if (!lockFileDir.exists()) {
lockFileDir.mkdirs();
}
File lockFile = new File(lockFileDir, crawlType + "-crawl.lock");
try {
// if lock file doesn't exist, create it
if (!lockFile.exists()) {
lockFile.createNewFile();
}
@ -165,6 +172,7 @@ public abstract class Crawler {
// Try acquiring the lock without blocking. This method returns
// null or throws an exception if the file is already locked.
FileLock lock = channel.tryLock();
if (lock == null) {
// Someone else has the lock
statusHandler

View file

@ -8,7 +8,6 @@ import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import com.google.common.annotations.VisibleForTesting;
import com.raytheon.uf.common.datadelivery.registry.Collection;
@ -278,9 +277,8 @@ public class MainSequenceCrawler extends Crawler {
if (!coll.isIgnore()) {
List<Date> datesToCrawl = new ArrayList<Date>();
Date date = TimeUtil.newImmutableDate();
long postedFileDelayMilliseconds = TimeUnit.MILLISECONDS
.convert(provider.getPostedFileDelayValue(),
provider.getPostedFileDelayUnits());
long postedFileDelayMilliseconds = provider
.getPostedFileDelay().getMillis();
if (postedFileDelayMilliseconds > 0) {
// Check whether the posted file delay would place us in

View file

@ -31,6 +31,8 @@ import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfig;
import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfigFixture;
@ -53,30 +55,13 @@ import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfigFixture
public class ProviderTest {
@Test
public void testSetPostedFileDelayAllowsSpacesSurrounding() {
Provider provider = new Provider();
provider.setPostedFileDelay(" 2 MICROSECONDS ");
assertEquals(2, provider.getPostedFileDelayValue());
assertEquals(TimeUnit.MICROSECONDS, provider.getPostedFileDelayUnits());
}
@Test
public void testSetPostedFileDelayCanParseText() {
Provider provider = new Provider();
provider.setPostedFileDelay("5 HOURS");
assertEquals(5, provider.getPostedFileDelayValue());
assertEquals(TimeUnit.HOURS, provider.getPostedFileDelayUnits());
}
@Test
public void testSetPostedFileDelayIsCalledOnJaxbUnmarshall()
throws JAXBException {
HarvesterConfig config = HarvesterConfigFixture.INSTANCE.get();
Provider provider = config.getProvider();
provider.setPostedFileDelay("3 DAYS");
final IDuration originalDuration = Durations.of(3, TimeUnit.DAYS);
provider.setPostedFileDelay(originalDuration);
Writer writer = new StringWriter();
JAXBContext ctx = JAXBContext.newInstance(HarvesterConfig.class);
@ -85,19 +70,6 @@ public class ProviderTest {
HarvesterConfig restored = (HarvesterConfig) ctx.createUnmarshaller()
.unmarshal(new StringReader(writer.toString()));
Provider restoredProvider = restored.getProvider();
assertEquals(3, restoredProvider.getPostedFileDelayValue());
assertEquals(TimeUnit.DAYS, restoredProvider.getPostedFileDelayUnits());
}
@Test(expected = IllegalArgumentException.class)
public void testSetPostedFileDelayThrowsExceptionOnInvalidUnits() {
Provider provider = new Provider();
provider.setPostedFileDelay("5 HOUR");
}
@Test(expected = IllegalArgumentException.class)
public void testSetPostedFileDelayThrowsExceptionOnValueLessThanZero() {
Provider provider = new Provider();
provider.setPostedFileDelay("-1 DAYS");
assertEquals(originalDuration, restoredProvider.getPostedFileDelay());
}
}

View file

@ -0,0 +1,302 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformFromThrift;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformToThrift;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.IDuration;
import com.raytheon.uf.common.util.TestUtil;
/**
* Test {@link Duration}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 10, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class DurationTest {
private static final long TWO_DAYS_IN_NANOS = TimeUnit.DAYS.toNanos(2);
private static final long TWO_DAYS_IN_MICROS = TimeUnit.DAYS.toMicros(2);
private static final long TWO_DAYS_IN_MILLIS = TimeUnit.DAYS.toMillis(2);
private static final long TWO_DAYS_IN_SECONDS = TimeUnit.DAYS.toSeconds(2);
private static final long TWO_DAYS_IN_MINUTES = TimeUnit.DAYS.toMinutes(2);
private static final long TWO_DAYS_IN_HOURS = TimeUnit.DAYS.toHours(2);
private static final long TWO_DAYS_IN_DAYS = TimeUnit.DAYS.toDays(2);
@Test
public void testNanosecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_NANOS,
TimeUnit.NANOSECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testNanosecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.NANOSECONDS);
assertThat(startValue, is(equalTo(duration.getNanos())));
assertThat(0L, is(equalTo(duration.getMicros())));
assertThat(0L, is(equalTo(duration.getMillis())));
assertThat(0L, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testMicrosecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_MICROS,
TimeUnit.MICROSECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testMicrosecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.MICROSECONDS);
assertThat(startValue, is(equalTo(duration.getMicros())));
assertThat(0L, is(equalTo(duration.getMillis())));
assertThat(0L, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testMillisecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_MILLIS,
TimeUnit.MILLISECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testMillisecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.MILLISECONDS);
assertThat(startValue, is(equalTo(duration.getMillis())));
assertThat(0L, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testSecondsConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_SECONDS, TimeUnit.SECONDS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testSecondsConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.SECONDS);
assertThat(startValue, is(equalTo(duration.getSeconds())));
assertThat(0L, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testMinutesConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_MINUTES, TimeUnit.MINUTES);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testMinutesConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.MINUTES);
assertThat(startValue, is(equalTo(duration.getMinutes())));
assertThat(0L, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testHoursConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_HOURS, TimeUnit.HOURS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testHoursConvertToZeroWhenNotEnoughOfTargetUnit() {
final long startValue = 5L;
IDuration duration = new Duration(startValue, TimeUnit.HOURS);
assertThat(startValue, is(equalTo(duration.getHours())));
assertThat(0L, is(equalTo(duration.getDays())));
}
@Test
public void testDaysConvertToEntireRange() {
IDuration duration = new Duration(TWO_DAYS_IN_DAYS, TimeUnit.DAYS);
assertThat(TWO_DAYS_IN_NANOS, is(equalTo(duration.getNanos())));
assertThat(TWO_DAYS_IN_MICROS, is(equalTo(duration.getMicros())));
assertThat(TWO_DAYS_IN_MILLIS, is(equalTo(duration.getMillis())));
assertThat(TWO_DAYS_IN_SECONDS, is(equalTo(duration.getSeconds())));
assertThat(TWO_DAYS_IN_MINUTES, is(equalTo(duration.getMinutes())));
assertThat(TWO_DAYS_IN_HOURS, is(equalTo(duration.getHours())));
assertThat(TWO_DAYS_IN_DAYS, is(equalTo(duration.getDays())));
}
@Test
public void testAddDurationReturnsCorrectAmount() {
IDuration dur1 = new Duration(2, TimeUnit.HOURS);
IDuration dur2 = new Duration(2, TimeUnit.DAYS);
assertThat(new Duration(50, TimeUnit.HOURS),
is(equalTo(dur1.plus(dur2))));
}
@Test
public void testSubtractDurationReturnsCorrectAmount() {
IDuration dur1 = new Duration(2, TimeUnit.DAYS);
IDuration dur2 = new Duration(2, TimeUnit.HOURS);
assertThat(new Duration(46, TimeUnit.HOURS),
is(equalTo(dur1.minus(dur2))));
}
@Test
public void testConversionToAndFromDynamicSerialize()
throws SerializationException {
IDuration original = new Duration(2, TimeUnit.DAYS);
UsesDuration usesDuration = new UsesDuration();
usesDuration.setDuration(original);
IDuration restored = transformFromThrift(UsesDuration.class,
transformToThrift(usesDuration)).getDuration();
assertThat(restored, is(equalTo(original)));
}
@Test
public void testConversionToAndFromJaxb() throws SerializationException,
JAXBException {
IDuration original = new Duration(2, TimeUnit.DAYS);
UsesDuration usesDuration = new UsesDuration();
usesDuration.setDuration(original);
JAXBManager manager = new JAXBManager(UsesDuration.class);
final String xml = manager.marshalToXml(usesDuration);
IDuration restored = ((UsesDuration) manager.unmarshalFromXml(xml))
.getDuration();
assertThat(restored, is(equalTo(original)));
}
@Test
public void testEqualsAndHashcodeContract() {
IDuration objectUnderTest = Durations.of(TWO_DAYS_IN_DAYS,
TimeUnit.DAYS);
List<IDuration> equalObjects = Arrays.asList(
Durations.of(TWO_DAYS_IN_HOURS, TimeUnit.HOURS),
Durations.of(TWO_DAYS_IN_MINUTES, TimeUnit.MINUTES),
Durations.of(TWO_DAYS_IN_SECONDS, TimeUnit.SECONDS));
List<IDuration> unequalObjects = Arrays.asList(
Durations.of(TWO_DAYS_IN_HOURS + 1, TimeUnit.HOURS),
Durations.of(TWO_DAYS_IN_MINUTES + 1, TimeUnit.MINUTES),
Durations.of(TWO_DAYS_IN_SECONDS + 1, TimeUnit.SECONDS));
TestUtil.assertEqualsAndHashcodeContract(objectUnderTest, equalObjects,
unequalObjects);
}
}

View file

@ -0,0 +1,94 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* Test {@link Durations}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class DurationsTest {
@Test
public void testParseFromString() {
IDuration duration = Durations.fromString("3 SECONDS");
assertThat(duration, is(equalTo(Durations.of(3, TimeUnit.SECONDS))));
}
@Test(expected = IllegalArgumentException.class)
public void testUnparseableStringThrowsException() {
Durations.fromString("unparseable");
}
@Test
public void testToStringWritesOutLargestUnitNotLosingPrecision() {
final String original = "3 SECONDS";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
@Test
public void testToStringForSmallestUnit() {
final String original = "1 NANOSECONDS";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
@Test
public void testToStringForLargestUnit() {
final String original = "7 DAYS";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
@Test
public void test128MinutesDoesNotUseHours() {
final String original = "128 MINUTES";
IDuration duration = Durations.fromString(original);
assertThat(Durations.toString(duration), is(equalTo(original)));
}
}

View file

@ -0,0 +1,157 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformFromThrift;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformToThrift;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.util.TestUtil;
/**
* Test {@link TimeInterval}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimeIntervalTest {
private final ITimePoint intervalStart = TimePoints.fromMillis(100L);
private final ITimePoint intervalEnd = TimePoints.fromMillis(500L);
private final ITimeInterval interval = new TimeInterval(intervalStart,
intervalEnd);
@Test
public void testConversionToAndFromDynamicSerialize()
throws SerializationException {
UsesTimeInterval usesTimeInterval = new UsesTimeInterval();
usesTimeInterval.setTimeInterval(interval);
ITimeInterval restored = transformFromThrift(UsesTimeInterval.class,
transformToThrift(usesTimeInterval)).getTimeInterval();
assertThat(restored, is(equalTo(interval)));
}
@Test
public void testConversionToAndFromJaxb() throws SerializationException,
JAXBException {
UsesTimeInterval usesTimeInterval = new UsesTimeInterval();
usesTimeInterval.setTimeInterval(interval);
JAXBManager manager = new JAXBManager(UsesTimeInterval.class);
final String xml = manager.marshalToXml(usesTimeInterval);
ITimeInterval restored = ((UsesTimeInterval) manager
.unmarshalFromXml(xml)).getTimeInterval();
assertThat(restored, is(equalTo(interval)));
}
@Test
public void testGetStartReturnsCorrectTimePoint() {
assertThat(interval.getStart(), is(equalTo(intervalStart)));
}
@Test
public void testGetEndReturnsCorrectTimePoint() {
assertThat(interval.getEnd(), is(equalTo(intervalEnd)));
}
@Test
public void testContainsTimePointReturnsTrueForMidPointWithinInterval() {
final ITimePoint withinInterval = TimePoints.fromMillis((intervalStart
.asMilliseconds() + intervalEnd.asMilliseconds()) / 2);
assertTrue(
"The interval should have returned true for a time point contained in it!",
interval.containsTimePoint(withinInterval));
}
@Test
public void testContainsTimePointReturnsTrueForIntervalStart() {
assertTrue(
"The interval should have returned true for a time point contained in it!",
interval.containsTimePoint(intervalStart));
}
@Test
public void testContainsTimePointReturnsTrueForIntervalEnd() {
assertTrue(
"The interval should have returned true for a time point contained in it!",
interval.containsTimePoint(intervalEnd));
}
@Test
public void testGetDurationReturnsCorrectAmount() {
assertThat(interval.getDuration(), is(equalTo(Durations.of(
intervalEnd.asMilliseconds() - intervalStart.asMilliseconds(),
TimeUnit.MILLISECONDS))));
}
@Test
public void testEqualsAndHashcodeContract() {
ITimeInterval sameInterval = new TimeInterval(
TimePoints.fromMillis(intervalStart.asMilliseconds()),
TimePoints.fromMillis(intervalEnd.asMilliseconds()));
List<ITimeInterval> equalObjects = Arrays
.<ITimeInterval> asList(sameInterval);
ITimeInterval startOneMillisecondEarlier = new TimeInterval(
TimePoints.fromMillis(intervalStart.asMilliseconds() - 1L),
TimePoints.fromMillis(intervalEnd.asMilliseconds()));
ITimeInterval endOneMillisecondLater = new TimeInterval(
TimePoints.fromMillis(intervalStart.asMilliseconds()),
TimePoints.fromMillis(intervalEnd.asMilliseconds() + 1L));
List<ITimeInterval> unequalObjects = Arrays.<ITimeInterval> asList(
startOneMillisecondEarlier, endOneMillisecondLater);
TestUtil.assertEqualsAndHashcodeContract(interval, equalObjects,
unequalObjects);
}
}

View file

@ -0,0 +1,48 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import org.junit.Test;
/**
* Test {@link TimeIntervals}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimeIntervalsTest {
@Test(expected = IllegalArgumentException.class)
public void testEndCantBeBeforeStart() {
TimeIntervals.fromTimePoints(TimePoints.fromMillis(20L),
TimePoints.fromMillis(10L));
}
}

View file

@ -0,0 +1,202 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformFromThrift;
import static com.raytheon.uf.common.serialization.SerializationUtil.transformToThrift;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.util.TestUtil;
/**
* Test {@link TimePoint}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimePointTest {
private final ITimePoint earlierPoint = new TimePoint(1L);
private final ITimePoint laterPoint = new TimePoint(2L);
private final ITimePoint sameAsEarlierPoint = new TimePoint(earlierPoint);
@Test
public void testConversionToAndFromDynamicSerialize()
throws SerializationException {
UsesTimePoint usesTimePoint = new UsesTimePoint();
usesTimePoint.setTimePoint(laterPoint);
ITimePoint restored = transformFromThrift(UsesTimePoint.class,
transformToThrift(usesTimePoint)).getTimePoint();
assertThat(restored, is(equalTo(laterPoint)));
}
@Test
public void testConversionToAndFromJaxb() throws SerializationException,
JAXBException {
UsesTimePoint usesTimePoint = new UsesTimePoint();
usesTimePoint.setTimePoint(laterPoint);
JAXBManager manager = new JAXBManager(UsesTimePoint.class);
final String xml = manager.marshalToXml(usesTimePoint);
ITimePoint restored = ((UsesTimePoint) manager.unmarshalFromXml(xml))
.getTimePoint();
assertThat(restored, is(equalTo(laterPoint)));
}
@Test
public void testAsDateReturnsSameInstance() {
Date date = new Date();
TimePoint timePoint = new TimePoint(date.getTime());
assertThat(timePoint.asDate(), is(equalTo(date)));
}
@Test
public void testAsMillisecondsReturnsOriginalValue() {
final long originalMillis = TimeUtil.currentTimeMillis();
TimePoint timePoint = new TimePoint(originalMillis);
assertThat(timePoint.asMilliseconds(), is(equalTo(originalMillis)));
}
@Test
public void testIsAfterReturnsTrueWhenLater() {
assertTrue("The later point should have been recognized as later!",
laterPoint.isAfter(earlierPoint));
}
@Test
public void testIsAfterReturnsFalseWhenEarlier() {
assertFalse(
"The earlier point should have been recognized as not later!",
earlierPoint.isAfter(laterPoint));
}
@Test
public void testIsAfterReturnsFalseWhenSameTime() {
assertFalse(
"The earlier point should have been recognized as not later!",
sameAsEarlierPoint.isAfter(laterPoint));
}
@Test
public void testIsBeforeReturnsTrueWhenEarlier() {
assertTrue("The earlier point should have been recognized as earlier!",
earlierPoint.isBefore(laterPoint));
}
@Test
public void testIsBeforeReturnsFalseWhenLater() {
assertFalse(
"The later point should have been recognized as not earlier!",
laterPoint.isBefore(earlierPoint));
}
@Test
public void testIsBeforeReturnsFalseWhenSameTime() {
assertFalse(
"The same time point should have been recognized as not earlier!",
sameAsEarlierPoint.isBefore(earlierPoint));
}
@Test
public void testIsSameReturnsFalseWhenEarlier() {
assertFalse("The earlier point should not have been the same!",
earlierPoint.isSame(laterPoint));
}
@Test
public void testIsSameReturnsFalseWhenLater() {
assertFalse("The later point should not have been the same!",
laterPoint.isSame(earlierPoint));
}
@Test
public void testIsSameReturnsTrueWhenSameTime() {
assertTrue(
"The same time point should have been recognized as the same time!",
sameAsEarlierPoint.isSame(earlierPoint));
}
@Test
public void testIsWithinReturnsTrueForTimeIntervalThatContainsIt() {
ITimeInterval interval = TimeIntervals.fromTimePoints(earlierPoint,
laterPoint);
assertTrue(
"The time point should have returned true for being within the interval",
earlierPoint.isWithin(interval));
}
@Test
public void testIsWithinReturnsFalseForTimeIntervalThatDoesntContainIt() {
ITimeInterval interval = TimeIntervals.fromTimePoints(earlierPoint,
laterPoint);
assertFalse(
"The time point should have returned false for being within the interval",
new TimePoint(earlierPoint.asMilliseconds() - 1L)
.isWithin(interval));
}
@Test
public void testEqualsAndHashcodeContract() {
List<ITimePoint> equalObjects = Arrays.asList(sameAsEarlierPoint);
List<ITimePoint> unequalObjects = Arrays.asList(laterPoint,
TimePoints.now());
TestUtil.assertEqualsAndHashcodeContract(earlierPoint, equalObjects,
unequalObjects);
}
}

View file

@ -0,0 +1,70 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.time.util.TimeUtilTest;
/**
* Test {@link TimePoints}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TimePointsTest {
@Before
public void setUp() {
TimeUtilTest.freezeTime();
}
@After
public void tearDown() {
TimeUtilTest.resumeTime();
}
@Test
public void testNowReturnsCurrentTime() {
long expectedTime = TimeUtil.currentTimeMillis();
assertThat(TimePoints.now(),
is(equalTo(TimePoints.fromMillis(expectedTime))));
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.junit.Ignore;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.api.IDuration;
/**
* Uses an {@link IDuration}. Used by {@link DurationTest} to verify Jaxb
* interoperability.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class UsesDuration {
@DynamicSerializeElement
@XmlElement
private IDuration duration;
/**
* @return the duration
*/
public IDuration getDuration() {
return duration;
}
/**
* @param duration
* the duration to set
*/
public void setDuration(IDuration duration) {
this.duration = duration;
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.junit.Ignore;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.api.ITimeInterval;
/**
* Uses an {@link ITimeInterval}. Used by {@link TimeIntervalTest} to verify
* Jaxb interoperability.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class UsesTimeInterval {
@DynamicSerializeElement
@XmlElement
private ITimeInterval timeInterval;
/**
* @return the timeInterval
*/
public ITimeInterval getTimeInterval() {
return timeInterval;
}
/**
* @param timeInterval
* the timeInterval to set
*/
public void setTimeInterval(ITimeInterval timeInterval) {
this.timeInterval = timeInterval;
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.time.domain;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.junit.Ignore;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.domain.api.ITimePoint;
/**
* Uses an {@link ITimePoint}. Used by {@link TimePointTest} to verify Jaxb
* interoperability.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 11, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class UsesTimePoint {
@DynamicSerializeElement
@XmlElement
private ITimePoint timePoint;
/**
* @return the timePoint
*/
public ITimePoint getTimePoint() {
return timePoint;
}
/**
* @param timePoint
* the timePoint to set
*/
public void setTimePoint(ITimePoint timePoint) {
this.timePoint = timePoint;
}
}

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.edex.datadelivery.harvester;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
@ -30,6 +31,7 @@ import org.junit.Test;
import org.mockito.Mockito;
import com.raytheon.uf.common.localization.PathManagerFactoryTest;
import com.raytheon.uf.common.time.domain.Durations;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.time.util.TimeUtilTest;
import com.raytheon.uf.edex.datadelivery.harvester.config.HarvesterConfig;
@ -105,7 +107,8 @@ public class CrawlerTest {
TimeUtilTest.freezeTime(time);
HarvesterConfig harvesterConfig = HarvesterConfigFixture.INSTANCE.get();
harvesterConfig.getProvider().setPostedFileDelay("3 DAYS");
harvesterConfig.getProvider().setPostedFileDelay(
Durations.of(3, TimeUnit.DAYS));
MainSequenceCrawler crawler = new MainSequenceCrawler(harvesterConfig,
mockCommunicationStrategy);
List<ModelCrawlConfiguration> modelCrawlConfigs = crawler
@ -129,7 +132,7 @@ public class CrawlerTest {
TimeUtilTest.freezeTime(time);
HarvesterConfig harvesterConfig = HarvesterConfigFixture.INSTANCE.get();
harvesterConfig.getProvider().setPostedFileDelay("2 MILLISECONDS");
harvesterConfig.getProvider().setPostedFileDelay(Durations.of(2, TimeUnit.MILLISECONDS));
MainSequenceCrawler crawler = new MainSequenceCrawler(harvesterConfig,
mockCommunicationStrategy);
List<ModelCrawlConfiguration> modelCrawlConfigs = crawler

View file

@ -0,0 +1,85 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.datadelivery.subscription.xml;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import com.raytheon.uf.common.datadelivery.registry.SubscriptionFixture;
import com.raytheon.uf.common.util.CollectionUtil;
import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
/**
* Test {@link LatencyRulesXML}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class LatencyRuleXMLTest {
/**
* Rule data size units were being written out as "Byte" but expected to be
* BYTE when running matches.
*
* @throws JAXBException
*/
@Test
public void testDataSizeUnitCanBeUsedInMatches() throws JAXBException {
LatencyRuleXML ruleXml = new LatencyRuleXML();
ruleXml.setLatency(10);
ruleXml.setRuleField(OpsNetFieldNames.SIZE.toString());
ruleXml.setRuleName("ruleName");
ruleXml.setRuleOperator(OperatorTypes.GREATER_THAN);
ruleXml.setRuleUnit(DataSizeUnit.BYTE.getUnit());
ruleXml.setRuleValue("10");
ruleXml.matches(SubscriptionFixture.INSTANCE.get(),
CollectionUtil.asSet(1, 2));
}
@Test
public void testFrequencyUnitCanBeUsedInMatches() throws JAXBException {
LatencyRuleXML ruleXml = new LatencyRuleXML();
ruleXml.setLatency(10);
ruleXml.setRuleField(OpsNetFieldNames.FREQUENCY.toString());
ruleXml.setRuleName("ruleName");
ruleXml.setRuleOperator(OperatorTypes.GREATER_THAN);
ruleXml.setRuleUnit(FreqUnitOptions.MIN.getOperation());
ruleXml.setRuleValue("10");
ruleXml.matches(SubscriptionFixture.INSTANCE.get(),
CollectionUtil.asSet(1, 2));
}
}

View file

@ -0,0 +1,75 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.datadelivery.subscription.xml;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
/**
* Test {@link OperatorAdapter}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class OperatorAdapterTest {
@Test
public void testMarshalUnmarshalOperatorNameOperationItems() {
verifyOperatorsUnmarshalAsSameOperator(NameOperationItems.values());
}
@Test
public void testMarshalUnmarshalOperatorOperatorTypes() {
verifyOperatorsUnmarshalAsSameOperator(OperatorTypes.values());
}
@Test
public void testMarshalUnmarshalOperatorTypeOperationItems() {
verifyOperatorsUnmarshalAsSameOperator(TypeOperationItems.values());
}
private void verifyOperatorsUnmarshalAsSameOperator(Operator... operators) {
for (Operator operator : operators) {
assertThat(operator,
is(sameInstance(OperatorAdapter.fromString(OperatorAdapter
.toString(operator)))));
}
}
}

View file

@ -31,6 +31,7 @@ import org.junit.Test;
import com.raytheon.uf.common.datadelivery.registry.DataType;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
@ -46,7 +47,8 @@ import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 3, 2013 1420 mpduff Initial creation.
* Jan 03, 2013 1420 mpduff Initial creation.
* Jan 14, 2013 1286 djohnson Use the rule operator as an {@link Operator}.
*
* </pre>
*
@ -70,7 +72,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("GFS");
rule.setRuleField(OpsNetFieldNames.NAME.getFieldName());
rule.setRuleOperator(NameOperationItems.LIKE.getOperation());
rule.setRuleOperator(NameOperationItems.LIKE);
assertTrue("Matches Data Set Name failed", rule.matches(sub, null));
}
@ -80,7 +82,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("GFS2");
rule.setRuleField(OpsNetFieldNames.NAME.getFieldName());
rule.setRuleOperator(NameOperationItems.LIKE.getOperation());
rule.setRuleOperator(NameOperationItems.LIKE);
assertFalse("Matches Data Set Name false positive",
rule.matches(sub, null));
@ -91,7 +93,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("GRID,OBS");
rule.setRuleField(OpsNetFieldNames.TYPE.getFieldName());
rule.setRuleOperator(TypeOperationItems.IN.getOperation());
rule.setRuleOperator(TypeOperationItems.IN);
assertTrue("Matches Data Type In Failed", rule.matches(sub, null));
}
@ -101,7 +103,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue("FAKE");
rule.setRuleField(OpsNetFieldNames.TYPE.getFieldName());
rule.setRuleOperator(TypeOperationItems.NOT_IN.getOperation());
rule.setRuleOperator(TypeOperationItems.NOT_IN);
assertTrue("Matches Data Type Not In Failed", rule.matches(sub, null));
}
@ -111,7 +113,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(100));
rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(DataSizeUnit.KB.getUnit());
assertTrue("Matches Dataset Size Equals Failed",
@ -123,7 +125,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(100));
rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(DataSizeUnit.MB.getUnit());
sub.setDataSetSize(1024 * 100);
@ -136,7 +138,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(100));
rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(DataSizeUnit.GB.getUnit());
sub.setDataSetSize(100 * 1024 * 1024);
@ -151,7 +153,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(60));
rule.setRuleField(OpsNetFieldNames.FREQUENCY.getFieldName());
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(FreqUnitOptions.MIN.getOperation());
Set<Integer> cycles = new TreeSet<Integer>();
@ -167,7 +169,7 @@ public class RuleXMLTest {
LatencyRuleXML rule = new LatencyRuleXML();
rule.setRuleValue(String.valueOf(1));
rule.setRuleField("Dataset Frequency");
rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
rule.setRuleOperator(OperatorTypes.EQUAL);
rule.setRuleUnit(FreqUnitOptions.HOURS.getOperation());
Set<Integer> cycles = new TreeSet<Integer>();

View file

@ -0,0 +1,69 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.datadelivery.utils;
import static com.google.common.collect.Lists.newArrayList;
import java.util.List;
import org.junit.Test;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.SubscriptionFixture;
import com.raytheon.uf.common.datadelivery.registry.Time;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 14, 2013 1286 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class DataDeliveryUtilsTest {
/**
* The method was throwing {@link IndexOutOfBoundsException}, this will
* prevent that regression.
*/
@Test
public void testMaxLatencyDoesntOverrunListIndex() {
List<Integer> cycleTimes = newArrayList();
cycleTimes.add(0);
cycleTimes.add(1);
cycleTimes.add(2);
Subscription subscription = SubscriptionFixture.INSTANCE.get();
Time subTime = subscription.getTime();
subTime.setCycleTimes(cycleTimes);
DataDeliveryUtils.getMaxLatency(subscription);
}
}