Merge "Add memory usage to integration tests [UPDATED]"
[cps.git] / cps-ncmp-rest / src / main / java / org / onap / cps / ncmp / rest / mapper / CmHandleStateMapper.java
index 933ca88..b436540 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.cps.ncmp.rest.mapper;
 
+import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING;
+
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 import org.mapstruct.Named;
 import org.mapstruct.NullValueCheckStrategy;
 import org.mapstruct.NullValuePropertyMappingStrategy;
-import org.onap.cps.ncmp.api.inventory.CompositeState;
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
 import org.onap.cps.ncmp.rest.model.CmHandleCompositeState;
 import org.onap.cps.ncmp.rest.model.DataStores;
+import org.onap.cps.ncmp.rest.model.LockReason;
 import org.onap.cps.ncmp.rest.model.SyncState;
 
 @Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
@@ -35,8 +38,8 @@ import org.onap.cps.ncmp.rest.model.SyncState;
 public interface CmHandleStateMapper {
 
     @Mapping(target = "dataSyncState", source = "dataStores", qualifiedByName = "dataStoreToDataSyncState")
-    @Mapping(target = "lockReason.reason", source = "lockReason.lockReasonCategory")
-    CmHandleCompositeState toCmHandleCompositeState(CompositeState compositeState);
+    @Mapping(target = "lockReason", source = "lockReason", qualifiedByName = "toExternalLockReason")
+    CmHandleCompositeState toCmHandleCompositeStateExternalLockReason(CompositeState compositeState);
 
     /**
      * Convert from CompositeState datastore to RestOutput Datastores.
@@ -55,14 +58,32 @@ public interface CmHandleStateMapper {
 
         if (compositeStateDataStore.getOperationalDataStore() != null) {
             final SyncState operationalSyncState = new SyncState();
-            operationalSyncState.setState(compositeStateDataStore.getOperationalDataStore().getSyncState().name());
+            operationalSyncState.setSyncState(compositeStateDataStore.getOperationalDataStore()
+                    .getDataStoreSyncState().name());
             operationalSyncState.setLastSyncTime(compositeStateDataStore.getOperationalDataStore().getLastSyncTime());
             dataStores.setOperational(operationalSyncState);
         }
 
-
         return dataStores;
+    }
 
+    /**
+     * Convert Internal Lock Reason to External Lock Reason.
+     *
+     * @param internalLockReason Internal Lock Reason
+     *
+     * @return externalLockReason
+     */
+    @Named("toExternalLockReason")
+    static LockReason toExternalLockReason(CompositeState.LockReason internalLockReason) {
+        final LockReason externalLockReason = new LockReason();
+        if (internalLockReason.getLockReasonCategory() == null) {
+            externalLockReason.setReason(LOCKED_MISBEHAVING.name());
+        } else {
+            externalLockReason.setReason(internalLockReason.getLockReasonCategory().name());
+        }
+        externalLockReason.setDetails(internalLockReason.getDetails());
+        return externalLockReason;
     }
 
 }