import java.time.OffsetDateTime;
import java.util.Collection;
+import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.exceptions.DataValidationException;
+import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
+@AllArgsConstructor
public class CpsDataServiceImpl implements CpsDataService {
private static final String ROOT_NODE_XPATH = "/";
- @Autowired
- private CpsDataPersistenceService cpsDataPersistenceService;
-
- @Autowired
- private CpsAdminService cpsAdminService;
-
- @Autowired
- private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
-
- @Autowired
- private NotificationService notificationService;
+ private final CpsDataPersistenceService cpsDataPersistenceService;
+ private final CpsAdminService cpsAdminService;
+ private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
+ private final NotificationService notificationService;
@Override
public void saveData(final String dataspaceName, final String anchorName, final String jsonData,
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, dataNodeXpath, Operation.DELETE);
}
+ @Override
+ public void deleteDataNodes(final String dataspaceName, final String anchorName,
+ final OffsetDateTime observedTimestamp) {
+ final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName);
+ processDataUpdatedEventAsync(anchor, ROOT_NODE_XPATH, Operation.DELETE, observedTimestamp);
+ }
+
@Override
public void deleteListOrListElement(final String dataspaceName, final String anchorName, final String listNodeXpath,
final OffsetDateTime observedTimestamp) {
private void processDataUpdatedEventAsync(final String dataspaceName, final String anchorName,
final OffsetDateTime observedTimestamp, final String xpath,
final Operation operation) {
+ final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ this.processDataUpdatedEventAsync(anchor, xpath, operation, observedTimestamp);
+ }
+
+ private void processDataUpdatedEventAsync(final Anchor anchor, final String xpath, final Operation operation,
+ final OffsetDateTime observedTimestamp) {
try {
- notificationService.processDataUpdatedEvent(dataspaceName, anchorName, observedTimestamp, xpath, operation);
+ notificationService.processDataUpdatedEvent(anchor, observedTimestamp, xpath, operation);
} catch (final Exception exception) {
+ //If async message can't be queued for notification service, the initial request should not failed.
log.error("Failed to send message to notification service", exception);
}
}