summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java35
1 files changed, 32 insertions, 3 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java
index 9e12d0dec9..f90ef79290 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java
@@ -1,17 +1,35 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.openecomp.sdc.versioning.dao.impl;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.ItemVersion;
import com.amdocs.zusammen.datatypes.itemversion.Tag;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Optional;
+import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.core.zusammen.api.ZusammenUtil;
import org.openecomp.sdc.versioning.dao.VersionableEntityDao;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
-import java.util.Optional;
-
public class VersionableEntityDaoZusammenImpl implements VersionableEntityDao {
private ZusammenAdaptor zusammenAdaptor;
@@ -47,9 +65,20 @@ public class VersionableEntityDaoZusammenImpl implements VersionableEntityDao {
// TODO: 3/19/2017 move to a common util
private Id getItemVersionId(Id itemId, SessionContext context) {
- Optional<ItemVersion> itemVersionOptional = zusammenAdaptor.getFirstVersion(context, itemId);
+ Optional<ItemVersion> itemVersionOptional = getFirstVersion(context, itemId);
ItemVersion itemVersion = itemVersionOptional.orElseThrow(() ->
new RuntimeException(String.format("No version was found for item %s.", itemId)));
return itemVersion.getId();
}
+
+ private Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) {
+ Collection<ItemVersion> versions = zusammenAdaptor.listPublicVersions(context, itemId);
+ return CollectionUtils.isEmpty(versions)
+ ? Optional.empty()
+ : versions.stream().min(getVersionModificationTimeDescComparator());
+ }
+
+ private static Comparator<ItemVersion> getVersionModificationTimeDescComparator() {
+ return (o1, o2) -> Integer.compare(o2.getId().getValue().length(), o1.getId().getValue().length());
+ }
}