use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class InternalResource method createApplication.
@POST
@Path("/applications")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Transactional
@RolesAllowed(ConsoleIdentityProvider.RBAC_INTERNAL_USER)
public Application createApplication(@Context SecurityContext sec, @NotNull @Valid AddApplicationRequest request) {
securityContextUtil.hasPermissionForRole(sec, request.ownerRole);
Application app = new Application();
app.setBundleId(request.bundleId);
app.setDisplayName(request.displayName);
app.setName(request.name);
app = applicationRepository.createApp(app);
if (request.ownerRole != null) {
InternalRoleAccess access = new InternalRoleAccess();
access.setRole(request.ownerRole);
access.setApplicationId(app.getId());
access.setApplication(app);
internalRoleAccessRepository.addAccess(access);
}
return app;
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class TemplateRepository method createAggregationEmailTemplate.
@Transactional
public AggregationEmailTemplate createAggregationEmailTemplate(AggregationEmailTemplate template) {
Template subjectTemplate = findTemplate(template.getSubjectTemplateId(), SUBJECT_NOT_FOUND);
Template bodyTemplate = findTemplate(template.getBodyTemplateId(), BODY_NOT_FOUND);
template.setSubscriptionType(template.getSubscriptionType());
template.setSubjectTemplate(subjectTemplate);
template.setBodyTemplate(bodyTemplate);
if (template.getApplicationId() != null) {
Application app = findApplication(template.getApplicationId());
template.setApplication(app);
}
entityManager.persist(template);
// The full application isn't needed in the REST response.
template.filterOutApplication();
// The full templates aren't needed in the REST response.
template.filterOutTemplates();
return template;
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class TemplateRepository method updateAggregationEmailTemplate.
@Transactional
public boolean updateAggregationEmailTemplate(UUID id, AggregationEmailTemplate template) {
String hql = "UPDATE AggregationEmailTemplate SET application = :app, subjectTemplate = :subjectTemplate, " + "subscriptionType = :subscriptionType, bodyTemplate = :bodyTemplate WHERE id = :id";
Application app;
if (template.getApplicationId() == null) {
app = null;
} else {
app = findApplication(template.getApplicationId());
}
Template subjectTemplate = findTemplate(template.getSubjectTemplateId(), SUBJECT_NOT_FOUND);
Template bodyTemplate = findTemplate(template.getBodyTemplateId(), BODY_NOT_FOUND);
int rowCount = entityManager.createQuery(hql).setParameter("app", app).setParameter("subscriptionType", template.getSubscriptionType()).setParameter("subjectTemplate", subjectTemplate).setParameter("bodyTemplate", bodyTemplate).setParameter("id", id).executeUpdate();
return rowCount > 0;
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class CrudTestHelpers method buildApp.
public static Application buildApp(String bundleId, String name, String displayName) {
Application app = new Application();
if (bundleId != null) {
app.setBundleId(UUID.fromString(bundleId));
}
app.setName(name);
app.setDisplayName(displayName);
return app;
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class ResourceHelpers method createTestAppAndEventTypes.
public UUID createTestAppAndEventTypes() {
Bundle bundle = createBundle(TEST_BUNDLE_NAME, "...");
Application app1 = createApplication(bundle.getId(), TEST_APP_NAME, "...");
for (int i = 0; i < 100; i++) {
String name = String.format(TEST_EVENT_TYPE_FORMAT, i);
String displayName = "... -> " + i;
String description = "Desc .. --> " + i;
createEventType(app1.getId(), name, displayName, description);
}
Application app2 = createApplication(bundle.getId(), TEST_APP_NAME_2, "...");
for (int i = 0; i < 100; i++) {
String name = String.format(TEST_EVENT_TYPE_FORMAT, i);
String displayName = "... -> " + i;
createEventType(app2.getId(), name, displayName, null);
}
return bundle.getId();
}
Aggregations