Search in sources :

Example 1 with Application

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;
}
Also used : InternalRoleAccess(com.redhat.cloud.notifications.models.InternalRoleAccess) Application(com.redhat.cloud.notifications.models.Application) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Transactional(javax.transaction.Transactional)

Example 2 with Application

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;
}
Also used : Application(com.redhat.cloud.notifications.models.Application) AggregationEmailTemplate(com.redhat.cloud.notifications.models.AggregationEmailTemplate) Template(com.redhat.cloud.notifications.models.Template) InstantEmailTemplate(com.redhat.cloud.notifications.models.InstantEmailTemplate) Transactional(javax.transaction.Transactional)

Example 3 with Application

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;
}
Also used : Application(com.redhat.cloud.notifications.models.Application) AggregationEmailTemplate(com.redhat.cloud.notifications.models.AggregationEmailTemplate) Template(com.redhat.cloud.notifications.models.Template) InstantEmailTemplate(com.redhat.cloud.notifications.models.InstantEmailTemplate) Transactional(javax.transaction.Transactional)

Example 4 with Application

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;
}
Also used : Application(com.redhat.cloud.notifications.models.Application)

Example 5 with Application

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();
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle) Application(com.redhat.cloud.notifications.models.Application) Endpoint(com.redhat.cloud.notifications.models.Endpoint)

Aggregations

Application (com.redhat.cloud.notifications.models.Application)32 Bundle (com.redhat.cloud.notifications.models.Bundle)15 EventType (com.redhat.cloud.notifications.models.EventType)14 QuarkusTest (io.quarkus.test.junit.QuarkusTest)11 Transactional (javax.transaction.Transactional)11 Test (org.junit.jupiter.api.Test)11 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)9 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)7 Header (io.restassured.http.Header)5 Response (io.restassured.response.Response)4 JsonArray (io.vertx.core.json.JsonArray)4 JsonObject (io.vertx.core.json.JsonObject)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 RhIdPrincipal (com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal)3 ApplicationRepository (com.redhat.cloud.notifications.db.repositories.ApplicationRepository)3 EmailSubscription (com.redhat.cloud.notifications.models.EmailSubscription)3 Endpoint (com.redhat.cloud.notifications.models.Endpoint)3 List (java.util.List)3 UUID (java.util.UUID)3