/*
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada
- * Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private LockReason lockReason;
private DataStores datastores;
private String lastUpdatedTime;
+ private Boolean dataSyncEnabled;
/**
* To create the {@link CompositeState}.
compositeState.setLockReason(lockReason);
compositeState.setDataStores(datastores);
compositeState.setLastUpdateTime(lastUpdatedTime);
+ compositeState.setDataSyncEnabled(dataSyncEnabled);
return compositeState;
}
/**
* To use attributes for creating {@link CompositeState}.
*
- * @param syncState for the locked state
+ * @param dataStoreSyncState for the locked state
* @param lastSyncTime for the locked state
* @return CompositeStateBuilder
*/
- public CompositeStateBuilder withOperationalDataStores(final SyncState syncState, final String lastSyncTime) {
+ public CompositeStateBuilder withOperationalDataStores(final DataStoreSyncState dataStoreSyncState,
+ final String lastSyncTime) {
this.datastores = DataStores.builder().operationalDataStore(
- Operational.builder().syncState(syncState).lastSyncTime(lastSyncTime).build()).build();
+ Operational.builder().dataStoreSyncState(dataStoreSyncState).lastSyncTime(lastSyncTime).build()).build();
return this;
}
* @return CompositeState
*/
public CompositeStateBuilder fromDataNode(final DataNode dataNode) {
- this.cmHandleState = CmHandleState.valueOf((String) dataNode.getLeaves()
- .get("cm-handle-state"));
+ this.cmHandleState = CmHandleState.valueOf((String) dataNode.getLeaves()
+ .get("cm-handle-state"));
+ this.lastUpdatedTime = (String) dataNode.getLeaves().get("last-update-time");
+ if (this.cmHandleState == CmHandleState.READY) {
+ this.dataSyncEnabled = (Boolean) dataNode.getLeaves().get("data-sync-enabled");
+ }
for (final DataNode stateChildNode : dataNode.getChildDataNodes()) {
if (stateChildNode.getXpath().endsWith("/lock-reason")) {
- this.lockReason = new LockReason(LockReasonCategory.valueOf(
- (String) stateChildNode.getLeaves().get("reason")),
- (String) stateChildNode.getLeaves().get("details"));
+ this.lockReason = getLockReason(stateChildNode);
}
if (stateChildNode.getXpath().endsWith("/datastores")) {
for (final DataNode dataStoreNodes : stateChildNode.getChildDataNodes()) {
Operational operationalDataStore = null;
if (dataStoreNodes.getXpath().contains("/operational")) {
- operationalDataStore = Operational.builder()
- .syncState(SyncState.valueOf((String) dataStoreNodes.getLeaves().get("sync-state")))
- .lastSyncTime((String) dataStoreNodes.getLeaves().get("last-sync-time"))
- .build();
+ operationalDataStore = getOperationalDataStore(dataStoreNodes);
}
this.datastores = DataStores.builder().operationalDataStore(operationalDataStore).build();
}
return this;
}
+ private Operational getOperationalDataStore(final DataNode dataStoreNodes) {
+ return Operational.builder()
+ .dataStoreSyncState(DataStoreSyncState.valueOf((String) dataStoreNodes.getLeaves().get("sync-state")))
+ .lastSyncTime((String) dataStoreNodes.getLeaves().get("last-sync-time"))
+ .build();
+ }
+
+ private LockReason getLockReason(final DataNode stateChildNode) {
+ final boolean isLockReasonExists = stateChildNode.getLeaves().containsKey("reason");
+ return new LockReason(isLockReasonExists
+ ? LockReasonCategory.valueOf((String) stateChildNode.getLeaves().get("reason"))
+ : null, (String) stateChildNode.getLeaves().get("details"));
+ }
+
}