private boolean updateSnapshot(Metadata metadata) throws MetadataException { final Versioning vs = metadata.getVersioning(); if (operand.getSnapshot() != null) { vs.setSnapshot(operand.getSnapshot()); } List<SnapshotVersion> extras = operand.getSnapshotVersions(); List<SnapshotVersion> currents = vs.getSnapshotVersions(); if (extras != null && extras.size() > 0) { // fix/upgrade the version ModelVersionUtility.setModelVersion(metadata, ModelVersionUtility.LATEST_MODEL_VERSION); for (SnapshotVersion extra : extras) { SnapshotVersion current = MetadataUtil.searchForEquivalent(extra, currents); if (current == null) { currents.add(extra); } else { try { if (TimeUtil.compare(current.getUpdated(), extra.getUpdated()) < 0) { currents.remove(current); currents.add(extra); } } catch (ParseException e) { throw new MetadataException( "Invalid timetamp: " + current.getUpdated() + "-" + extra.getUpdated(), e); } } } } else if (Version.V100 == operand.getOriginModelVersion()) { for (SnapshotVersion current : currents) { current.setUpdated(operand.getTimestamp()); } } vs.setLastUpdated(operand.getTimestamp()); return true; }
@Test public void testEmptyMetadataSetV100() { Metadata metadata = new Metadata(); ModelVersionUtility.setModelVersion(metadata, Version.V100); assertThat(ModelVersionUtility.getModelVersion(metadata), is(Version.V100)); }