Skip to content

Commit

Permalink
feat: added workspaceName to entity and provide list in endpoint (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter authored Feb 12, 2024
1 parent cdb1fb7 commit 4574eb8
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public class AnnouncementSearchCriteria {
private @Valid Integer pageNumber = 0;

private @Valid Integer pageSize = 100;

private @Valid String workspaceName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public PageResult<Announcement> loadAnnouncementByCriteria(AnnouncementSearchCri
if (criteria.getAppId() != null) {
predicates.add(cb.equal(root.get(Announcement_.APP_ID), criteria.getAppId()));
}
if (criteria.getWorkspaceName() != null) {
predicates.add(cb.equal(root.get(Announcement_.WORKSPACE_NAME), criteria.getWorkspaceName()));
}
if (criteria.getStartDateFrom() != null) {
predicates.add(cb.greaterThanOrEqualTo(root.get(Announcement_.START_DATE),
criteria.getStartDateFrom().toLocalDateTime()));
Expand Down Expand Up @@ -105,11 +108,26 @@ public List<String> findApplicationsWithAnnouncements() {
}
}

public List<String> findWorkspacesWithAnnouncements() {
try {
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createTupleQuery();
Root<Announcement> root = cq.from(Announcement.class);
cq.multiselect(root.get(Announcement_.WORKSPACE_NAME));
cq.distinct(true);
List<Tuple> tupleResult = getEntityManager().createQuery(cq).getResultList();
return tupleResult.stream().map(t -> (String) t.get(0)).toList();
} catch (Exception ex) {
throw new DAOException(ErrorKeys.ERROR_FIND_WORKSPACES_WITH_ANNOUNCEMENTS, ex);
}
}

public enum ErrorKeys {

FIND_ENTITY_BY_ID_FAILED,
ERROR_LOAD_ANNOUNCEMENT_BY_CRITERIA,
ERROR_FIND_APPLICATIONS_WITH_ANNOUNCEMENTS
ERROR_FIND_APPLICATIONS_WITH_ANNOUNCEMENTS,
ERROR_FIND_WORKSPACES_WITH_ANNOUNCEMENTS
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class Announcement extends TraceableEntity {
@Column(name = "appId")
private String appId;

@Column(name = "workspaceName")
private String workspaceName;

public enum Type {
EVENT,
INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public Response deleteAnnouncementById(String id) {
@Override

public Response getAllAppsWithAnnouncements() {
var items = dao.findApplicationsWithAnnouncements();
var results = mapper.map(items);
var appIds = dao.findApplicationsWithAnnouncements();
var workspaceNames = dao.findWorkspacesWithAnnouncements();
var results = mapper.map(appIds, workspaceNames);
return Response.ok(results).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
@Mapper(uses = OffsetDateTimeMapper.class)
public interface AnnouncementMapper {

default AnnouncementAppsDTO map(List<String> appIds) {
if (appIds == null) {
default AnnouncementAppsDTO map(List<String> appIds, List<String> workspaceNames) {
if (appIds == null && workspaceNames == null) {
return null;
}

AnnouncementAppsDTO dto = new AnnouncementAppsDTO();
dto.setAppIds(appIds);
if (appIds != null) {
dto.setAppIds(appIds);
}
if (workspaceNames != null) {
dto.setWorkspaceNames(workspaceNames);
}
return dto;
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/openapi/announcement-openapi-internal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ components:
type: array
items:
type: string
workspaceNames:
type: array
items:
type: string
CreateAnnouncementRequest:
type: object
required:
Expand All @@ -173,6 +177,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
AnnouncementSearchCriteria:
type: object
properties:
Expand All @@ -196,6 +202,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
pageNumber:
format: int32
description: The number of page.
Expand Down Expand Up @@ -232,6 +240,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
Announcement:
type: object
properties:
Expand Down Expand Up @@ -264,6 +274,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
AnnouncementPageResult:
type: object
properties:
Expand Down
2 changes: 2 additions & 0 deletions src/main/openapi/announcement-openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ components:
$ref: '#/components/schemas/OffsetDateTime'
appId:
type: string
workspaceName:
type: string
pageNumber:
format: int32
description: The number of page.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/v1/2023-12-11-create-tables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<constraints nullable="false"/>
</column>
<column name="appid" type="VARCHAR(255)"/>
<column name="workspaceName" type="VARCHAR(255)"/>
<column name="content" type="VARCHAR(255)"/>
<column name="creationuser" type="VARCHAR(255)"/>
<column name="modificationuser" type="VARCHAR(255)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ void methodExceptionTests() {
AnnouncementDAO.ErrorKeys.ERROR_FIND_APPLICATIONS_WITH_ANNOUNCEMENTS);
methodExceptionTests(() -> dao.loadAnnouncementByCriteria(null),
AnnouncementDAO.ErrorKeys.ERROR_LOAD_ANNOUNCEMENT_BY_CRITERIA);
methodExceptionTests(() -> dao.findWorkspacesWithAnnouncements(),
AnnouncementDAO.ErrorKeys.ERROR_FIND_WORKSPACES_WITH_ANNOUNCEMENTS);
}

void methodExceptionTests(Executable fn, Enum<?> key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ void getAllAnnouncementAppsTest() {
void getAnnouncementsByCriteriaOrg200Test() {
AnnouncementSearchCriteriaDTO criteria = new AnnouncementSearchCriteriaDTO();
criteria.setAppId("app2");
criteria.setWorkspaceName("workspace2");
criteria.status(AnnouncementStatusDTO.ACTIVE);
criteria.setPriority(AnnouncementPriorityTypeDTO.NORMAL);
criteria.setType(AnnouncementTypeDTO.EVENT);
Expand Down
20 changes: 10 additions & 10 deletions src/test/resources/data/test-internal.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<ANNOUNCEMENT guid="a1" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00"
appid="app1" content="some-content" priority="NORMAL" title="title1" type="EVENT" tenant_id="default"/>
appid="app1" content="some-content" priority="NORMAL" title="title1" type="EVENT" tenant_id="default" workspaceName="workspace1"/>

<ANNOUNCEMENT guid="a2" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a3" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title3" type="EVENT" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title3" type="EVENT" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a4" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="INACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title4" type="EVENT" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title4" type="EVENT" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a5" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title5" type="INFO" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title5" type="INFO" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a3-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a4-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="INACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a5-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="tenant-100"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="tenant-100" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a3-200" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-200"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-200" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a5-200" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="tenant-200"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="tenant-200" workspaceName="workspace2"/>
</dataset>
22 changes: 11 additions & 11 deletions src/test/resources/data/test-v1.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<ANNOUNCEMENT guid="a1" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00"
appid="app1" content="some-content" priority="NORMAL" title="title1" type="EVENT" tenant_id="default"/>
appid="app1" content="some-content" priority="NORMAL" title="title1" type="EVENT" tenant_id="default" workspaceName="workspace1"/>

<ANNOUNCEMENT guid="a2" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a3" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a4" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="INACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a5" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="default"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="default" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a3-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a4-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="INACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a5-100" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-100" workspaceName="workspace2"/>

<ANNOUNCEMENT guid="a3-200" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-200"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-200" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a4-200" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="INACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-200"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="EVENT" tenant_id="tenant-200" workspaceName="workspace2"/>
<ANNOUNCEMENT guid="a5-200" optlock="0" enddate="2022-02-05 06:01:00" startdate="2009-12-30 14:55:00" status="ACTIVE"
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="tenant-200"/>
appid="app2" content="some-content" priority="NORMAL" title="title2" type="INFO" tenant_id="tenant-200" workspaceName="workspace2"/>
</dataset>

0 comments on commit 4574eb8

Please sign in to comment.