public final class PatchDataTransactionUtil {
private static final Logger LOG = LoggerFactory.getLogger(PatchDataTransactionUtil.class);
- public PatchDataTransactionUtil() {
+ private PatchDataTransactionUtil() {
throw new UnsupportedOperationException("Util class.");
}
public static PATCHStatusContext patchData(final PATCHContext context, final TransactionVarsWrapper transactionNode,
final SchemaContextRef schemaContextRef) {
final List<PATCHStatusEntity> editCollection = new ArrayList<>();
- int errorCounter = 0;
+ boolean noError = true;
final DOMDataReadWriteTransaction tx = transactionNode.getTransactionChain().newReadWriteTransaction();
for (final PATCHEntity patchEntity : context.getData()) {
final PATCHEditOperation operation = PATCHEditOperation.valueOf(patchEntity.getOperation().toUpperCase());
-
- switch (operation) {
- case CREATE:
- if (errorCounter == 0) {
+ if (noError) {
+ switch (operation) {
+ case CREATE:
try {
createDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
patchEntity.getTargetNode(), patchEntity.getNode(), tx, schemaContextRef);
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
false, Lists.newArrayList(e.getErrors())));
- errorCounter++;
+ noError = false;
}
- }
- break;
- case DELETE:
- if (errorCounter == 0) {
+ break;
+ case DELETE:
try {
deleteDataWithinTransaction(LogicalDatastoreType.CONFIGURATION, patchEntity.getTargetNode(),
tx);
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
false, Lists.newArrayList(e.getErrors())));
- errorCounter++;
+ noError = false;
}
- }
- break;
- case MERGE:
- if (errorCounter == 0) {
+ break;
+ case MERGE:
try {
mergeDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
patchEntity.getTargetNode(), patchEntity.getNode(), tx, schemaContextRef);
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
false, Lists.newArrayList(e.getErrors())));
- errorCounter++;
+ noError = false;
}
- }
- break;
- case REPLACE:
- if (errorCounter == 0) {
+ break;
+ case REPLACE:
try {
replaceDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
patchEntity.getTargetNode(), patchEntity.getNode(), schemaContextRef, tx);
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
false, Lists.newArrayList(e.getErrors())));
- errorCounter++;
+ noError = false;
}
- }
- break;
- case REMOVE:
- if (errorCounter == 0) {
+ break;
+ case REMOVE:
try {
removeDataWithinTransaction(LogicalDatastoreType.CONFIGURATION, patchEntity.getTargetNode(),
tx);
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
false, Lists.newArrayList(e.getErrors())));
- errorCounter++;
+ noError = false;
}
- }
- break;
- default:
- editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
- false, Lists.newArrayList(new RestconfError(ErrorType.PROTOCOL,
- ErrorTag.OPERATION_NOT_SUPPORTED, "Not supported Yang PATCH operation"))));
- errorCounter++;
- break;
+ break;
+ default:
+ editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
+ false, Lists.newArrayList(new RestconfError(ErrorType.PROTOCOL,
+ ErrorTag.OPERATION_NOT_SUPPORTED, "Not supported Yang PATCH operation"))));
+ noError = false;
+ break;
+ }
+ } else {
+ break;
}
}
// if no errors then submit transaction, otherwise cancel
- if (errorCounter == 0) {
+ if (noError) {
final ResponseFactory response = new ResponseFactory();
final CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
} else {
tx.cancel();
RestConnectorProvider.resetTransactionChainForAdapaters(transactionNode.getTransactionChain());
- return new PATCHStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), false, null);
+ return new PATCHStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection),
+ false, null);
}
}
* @param path Path to be checked
*/
public static void checkItemExistsWithinTransaction(final DOMDataReadWriteTransaction rWTransaction,
- final LogicalDatastoreType store, final YangInstanceIdentifier path) {
+ final LogicalDatastoreType store, final YangInstanceIdentifier path) {
final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
* @param path Path to be checked
*/
public static void checkItemDoesNotExistsWithinTransaction(final DOMDataReadWriteTransaction rWTransaction,
- final LogicalDatastoreType store, final YangInstanceIdentifier path) {
+ final LogicalDatastoreType store, final YangInstanceIdentifier path) {
final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
"Data already exists", ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS, path);
}
}
-}
+}
\ No newline at end of file