use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method updateAndCheckBehaviorGroupActions.
@Transactional
void updateAndCheckBehaviorGroupActions(String accountId, UUID bundleId, UUID behaviorGroupId, Status expectedResult, UUID... endpointIds) {
Status status = behaviorGroupRepository.updateBehaviorGroupActions(accountId, behaviorGroupId, Arrays.asList(endpointIds));
// Is the update result the one we expected?
assertEquals(expectedResult, status);
if (expectedResult == Status.OK) {
// We need to clear the session L1 cache before checking the update result.
entityManager.clear();
// If we expected a success, the behavior group actions should match exactly the given endpoint IDs.
List<BehaviorGroupAction> actions = findBehaviorGroupActions(accountId, bundleId, behaviorGroupId);
assertEquals(endpointIds.length, actions.size());
for (int i = 0; i < endpointIds.length; i++) {
assertEquals(endpointIds[i], actions.get(i).getEndpoint().getId());
}
}
}
use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.
the class EndpointRepository method deleteEndpoint.
@Transactional
public boolean deleteEndpoint(String tenant, UUID id) {
String query = "DELETE FROM Endpoint WHERE accountId = :accountId AND id = :id";
int rowCount = entityManager.createQuery(query).setParameter("id", id).setParameter("accountId", tenant).executeUpdate();
return rowCount > 0;
// Actually, the endpoint targeting this should be repeatable
}
use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.
the class EndpointRepository method modifyEndpointStatus.
@Transactional
boolean modifyEndpointStatus(String tenant, UUID id, boolean enabled) {
String query = "UPDATE Endpoint SET enabled = :enabled WHERE accountId = :accountId AND id = :id";
int rowCount = entityManager.createQuery(query).setParameter("id", id).setParameter("accountId", tenant).setParameter("enabled", enabled).executeUpdate();
return rowCount > 0;
}
use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.
the class EndpointRepository method updateEndpoint.
@Transactional
public boolean updateEndpoint(Endpoint endpoint) {
// TODO Update could fail because the item did not exist, throw 404 in that case?
// TODO Fix transaction so that we don't end up with half the updates applied
String endpointQuery = "UPDATE Endpoint SET name = :name, description = :description, enabled = :enabled " + "WHERE accountId = :accountId AND id = :id";
String webhookQuery = "UPDATE WebhookProperties SET url = :url, method = :method, " + "disableSslVerification = :disableSslVerification, secretToken = :secretToken WHERE endpoint.id = :endpointId";
String camelQuery = "UPDATE CamelProperties SET url = :url, extras = :extras, " + "basicAuthentication = :basicAuthentication, " + "disableSslVerification = :disableSslVerification, secretToken = :secretToken WHERE endpoint.id = :endpointId";
if (endpoint.getType() == EndpointType.EMAIL_SUBSCRIPTION) {
throw new RuntimeException("Unable to update an endpoint of type EMAIL_SUBSCRIPTION");
}
int endpointRowCount = entityManager.createQuery(endpointQuery).setParameter("name", endpoint.getName()).setParameter("description", endpoint.getDescription()).setParameter("enabled", endpoint.isEnabled()).setParameter("accountId", endpoint.getAccountId()).setParameter("id", endpoint.getId()).executeUpdate();
if (endpointRowCount == 0) {
return false;
} else if (endpoint.getProperties() == null) {
return true;
} else {
switch(endpoint.getType()) {
case WEBHOOK:
WebhookProperties properties = endpoint.getProperties(WebhookProperties.class);
return entityManager.createQuery(webhookQuery).setParameter("url", properties.getUrl()).setParameter("method", properties.getMethod()).setParameter("disableSslVerification", properties.getDisableSslVerification()).setParameter("secretToken", properties.getSecretToken()).setParameter("endpointId", endpoint.getId()).executeUpdate() > 0;
case CAMEL:
CamelProperties cAttr = (CamelProperties) endpoint.getProperties();
return entityManager.createQuery(camelQuery).setParameter("url", cAttr.getUrl()).setParameter("disableSslVerification", cAttr.getDisableSslVerification()).setParameter("secretToken", cAttr.getSecretToken()).setParameter("endpointId", endpoint.getId()).setParameter("extras", cAttr.getExtras()).setParameter("basicAuthentication", cAttr.getBasicAuthentication()).executeUpdate() > 0;
default:
return true;
}
}
}
use of com.redhat.cloud.notifications.models.Endpoint in project notifications-backend by RedHatInsights.
the class LifecycleITest method addDefaultBehaviorGroupAction.
private void addDefaultBehaviorGroupAction(BehaviorGroup behaviorGroup) {
EmailSubscriptionProperties properties = new EmailSubscriptionProperties();
properties.setOnlyAdmins(true);
Endpoint endpoint = createEndpoint(null, EMAIL_SUBSCRIPTION, "Email endpoint", "System email endpoint", properties);
addBehaviorGroupAction(behaviorGroup.getId(), endpoint.getId());
}
Aggregations