Module Sync Lock State implementation
[cps.git] / cps-ncmp-rest / src / main / java / org / onap / cps / ncmp / rest / mapper / RestOutputCmHandleStateMapper.java
index 89015cc..5f4b311 100644 (file)
@@ -23,17 +23,19 @@ package org.onap.cps.ncmp.rest.mapper;
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 import org.mapstruct.Named;
-import org.onap.cps.ncmp.api.inventory.CmHandleState;
+import org.mapstruct.NullValueCheckStrategy;
+import org.mapstruct.NullValuePropertyMappingStrategy;
 import org.onap.cps.ncmp.api.inventory.CompositeState;
 import org.onap.cps.ncmp.rest.model.DataStores;
 import org.onap.cps.ncmp.rest.model.RestOutputCmHandleState;
 import org.onap.cps.ncmp.rest.model.SyncState;
 
-@Mapper(componentModel = "spring")
+@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
+        nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT)
 public interface RestOutputCmHandleStateMapper {
 
     @Mapping(target = "dataSyncState", source = "dataStores", qualifiedByName = "dataStoreToDataSyncState")
-    @Mapping(target = "cmHandleState", source = "cmhandleState", qualifiedByName = "cmHandleStateEnumToString")
+    @Mapping(target = "lockReason.reason", source = "lockReason.lockReasonCategory")
     RestOutputCmHandleState toRestOutputCmHandleState(CompositeState compositeState);
 
     /**
@@ -45,15 +47,12 @@ public interface RestOutputCmHandleStateMapper {
     @Named("dataStoreToDataSyncState")
     static DataStores toDataStores(CompositeState.DataStores compositeStateDataStore) {
 
-        final DataStores dataStores = new DataStores();
-
-        if (compositeStateDataStore.getRunningDataStore() != null) {
-            final SyncState runningSyncState = new SyncState();
-            runningSyncState.setState(compositeStateDataStore.getRunningDataStore().getSyncState());
-            runningSyncState.setLastSyncTime(compositeStateDataStore.getRunningDataStore().getLastSyncTime());
-            dataStores.setRunning(runningSyncState);
+        if (compositeStateDataStore == null) {
+            return null;
         }
 
+        final DataStores dataStores = new DataStores();
+
         if (compositeStateDataStore.getOperationalDataStore() != null) {
             final SyncState operationalSyncState = new SyncState();
             operationalSyncState.setState(compositeStateDataStore.getOperationalDataStore().getSyncState());
@@ -66,14 +65,4 @@ public interface RestOutputCmHandleStateMapper {
 
     }
 
-    /**
-     * Converts cmHandleState enum value to equivalent string.
-     * @param cmHandleState cm handle state enum
-     * @return cm handle state as string
-     */
-    @Named("cmHandleStateEnumToString")
-    static String toCmHandleState(final CmHandleState cmHandleState) {
-        return cmHandleState.name();
-    }
-
 }