@Override public void handleCreate(Operation post) { if (!checkForBody(post)) { return; } SslTrustCertificateState state = post.getBody(SslTrustCertificateState.class); if (state.documentVersion > 0) { post.complete(); return; } boolean validated = ValidationUtils.validate(post, () -> validateStateOnStart(state)); if (!validated) { return; } post.complete(); notifyLastUpdatedSslTrustDocumentService(); }
@Test public void testValidate() { Exception ex = new LocalizableValidationException("testValidate", "100"); FailHanldingOperation op = new FailHanldingOperation(); boolean isValid = ValidationUtils.validate(op, () -> { throw ex; }); assertFalse(isValid); assertEquals(ex, op.failure); op = new FailHanldingOperation(); isValid = ValidationUtils.validate(op, () -> { }); assertTrue(isValid); assertNull(op.failure); }
@Override public void handlePut(Operation put) { if (!checkForBody(put)) { return; } SslTrustCertificateState body = put.getBody(SslTrustCertificateState.class); SslTrustCertificateState state = getState(put); // these properties can't be modified once set: body.subscriptionLink = state.subscriptionLink; boolean validated = ValidationUtils.validate(put, () -> validateStateOnStart(body)); if (!validated) { return; } this.setState(put, body); put.setBody(body); if (isModified(put, state.certificate, body.certificate)) { put.complete(); notifyLastUpdatedSslTrustDocumentService(); } else { put.complete(); } }
@Override public void handlePatch(Operation patch) { if (!checkForBody(patch)) { return; } SslTrustCertificateState body = patch.getBody(SslTrustCertificateState.class); SslTrustCertificateState state = getState(patch); String stateCert = state.certificate; state.certificate = mergeProperty(state.certificate, body.certificate); boolean validated = ValidationUtils.validate(patch, () -> validateStateOnStart(state)); if (!validated) { return; } patch.setBody(state); if (isModified(patch, stateCert, body.certificate)) { patch.complete(); notifyLastUpdatedSslTrustDocumentService(); } else { patch.complete(); } }