From ac03e37c33de4d2bb0959baccfdcd69d2b6faab1 Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Sun, 4 Mar 2018 20:58:30 +0100 Subject: [PATCH 1/8] schedule event dirty implementation please refactor --- .../java/at/htl/utils/LayoutChangerUtil.java | 2 +- .../java/at/htl/xiboClient/DisplayApi.java | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java index 399f095..315337d 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java @@ -26,7 +26,7 @@ public void changeLayoutForAll(int layoutId) { /*for (int i = 0; i < displays.size(); i++) { displayApi.ChangeLayout(displays.get(i).getDisplayGroupId(), layoutId); }*/ - displayApi.ChangeLayout(11,layoutId); + displayApi.ScheduleLayout(11,layoutId); dataSetApi.collectNowAll(); } catch (NoConnectionException e) { e.printStackTrace(); diff --git a/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java b/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java index ae4c9c5..18050f8 100644 --- a/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java +++ b/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java @@ -9,12 +9,20 @@ import org.json.JSONObject; import javax.ejb.Stateless; +import javax.swing.text.DateFormatter; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.LinkedList; +import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME; + @Stateless public class DisplayApi { @@ -68,7 +76,10 @@ public LinkedList GetAllDisplays() throws NoConnectionException { return displays; } - public void ChangeLayout(long displayGroupId, int layoutId) throws NoConnectionException { + public void ScheduleLayout(LocalDateTime fromDate, LocalDateTime toDate) throws NoConnectionException { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); + BufferedReader in; LinkedList displays = new LinkedList<>(); Display act = new Display(); @@ -76,8 +87,9 @@ public void ChangeLayout(long displayGroupId, int layoutId) throws NoConnectionE //Get all Datasets HttpURLConnection con = new RequestHelper() .executeRequest(RequestTypeEnum.POST, - "layoutId=" + 21, - new RequestHelper().BASE_URL + "api/displaygroup/" + 14 + "/action/overlayLayout", + "eventTypeId=1&campaignId=" + 44 + + "&displayOrder=0&isPriority=11&displayGroupIds[]="+14+"&fromDt="+fromDate.format(formatter)+"&toDt="+toDate.format(formatter), + new RequestHelper().BASE_URL + "api/schedule", AuthentificationHandler.getTOKEN()); in = new BufferedReader(new InputStreamReader(con.getInputStream())); @@ -85,7 +97,6 @@ public void ChangeLayout(long displayGroupId, int layoutId) throws NoConnectionE String output; StringBuffer response = new StringBuffer(); while ((output = in.readLine()) != null) - { response.append(output); } From 17045292ccb5086a9f503b16d6b0fbcc58e2823f Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Sun, 4 Mar 2018 21:17:33 +0100 Subject: [PATCH 2/8] media filter added by tags, just showing project videos --- .../src/main/java/at/htl/utils/LayoutChangerUtil.java | 3 ++- HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java index 315337d..c426e91 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java @@ -8,6 +8,7 @@ import javax.ejb.Stateless; import javax.inject.Inject; +import java.time.LocalDateTime; import java.util.LinkedList; @Stateless @@ -26,7 +27,7 @@ public void changeLayoutForAll(int layoutId) { /*for (int i = 0; i < displays.size(); i++) { displayApi.ChangeLayout(displays.get(i).getDisplayGroupId(), layoutId); }*/ - displayApi.ScheduleLayout(11,layoutId); + displayApi.ScheduleLayout(LocalDateTime.now(),LocalDateTime.now().plusMinutes(2)); dataSetApi.collectNowAll(); } catch (NoConnectionException e) { e.printStackTrace(); diff --git a/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java b/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java index f5b493b..4d6b6f7 100644 --- a/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java +++ b/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java @@ -32,7 +32,7 @@ public LinkedList getAllMedia(int start, int length) throws NoConnectionE try { HttpURLConnection con = new RequestHelper() - .executeRequest(RequestTypeEnum.GET, null, + .executeRequest(RequestTypeEnum.GET, "tags=project", new RequestHelper().BASE_URL + "api/library?start=" + start +"&length="+length, AuthentificationHandler.getTOKEN()); try { From 0a56128558bcdfd9ac6adba6c29e959823fb3fa5 Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Sun, 4 Mar 2018 22:38:37 +0100 Subject: [PATCH 3/8] added tag cloud, lower sync time and so on --- .../main/java/at/htl/rest/MediaEndpoint.java | 6 +- .../main/java/at/htl/utils/RequestHelper.java | 8 +-- .../main/java/at/htl/utils/TimeService.java | 2 +- .../main/java/at/htl/web/IndexController.java | 2 +- .../main/java/at/htl/web/MediaController.java | 70 +++++++++++++++++-- .../main/java/at/htl/xiboClient/MediaApi.java | 10 ++- HomeDsBackend/src/main/webapp/media.xhtml | 5 +- 7 files changed, 82 insertions(+), 21 deletions(-) diff --git a/HomeDsBackend/src/main/java/at/htl/rest/MediaEndpoint.java b/HomeDsBackend/src/main/java/at/htl/rest/MediaEndpoint.java index 73d68a8..4ba7732 100644 --- a/HomeDsBackend/src/main/java/at/htl/rest/MediaEndpoint.java +++ b/HomeDsBackend/src/main/java/at/htl/rest/MediaEndpoint.java @@ -21,14 +21,14 @@ public class MediaEndpoint { @Produces(MediaType.APPLICATION_JSON) @Path("/") @ApiOperation("Get all Medias") - public Response getMedias(@QueryParam("start") int start, @QueryParam("length") int length) { + public Response getMedias(@QueryParam("start") int start, @QueryParam("length") int length, @QueryParam("tags") String tags) { try { if (length == 0 && start == 0) { - return Response.ok(mediaApi.getAllMedia(start, length)).build(); + return Response.ok(mediaApi.getAllMedia(start, length, tags)).build(); } else { - return Response.ok(mediaApi.getAllMedia(start, length)).build(); + return Response.ok(mediaApi.getAllMedia(start, length, tags)).build(); } } catch (NoConnectionException e) { e.printStackTrace(); diff --git a/HomeDsBackend/src/main/java/at/htl/utils/RequestHelper.java b/HomeDsBackend/src/main/java/at/htl/utils/RequestHelper.java index af1b9de..8fd8675 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/RequestHelper.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/RequestHelper.java @@ -33,10 +33,10 @@ public HttpURLConnection executeRequest(RequestTypeEnum executeType, String para case PUT: con.setRequestMethod("PUT"); con.setDoOutput(true); - DataOutputStream wr = new DataOutputStream(con.getOutputStream()); - wr.writeBytes(paramsBody); - wr.flush(); - wr.close(); + DataOutputStream wr2 = new DataOutputStream(con.getOutputStream()); + wr2.writeBytes(paramsBody); + wr2.flush(); + wr2.close(); break; case POST: diff --git a/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java b/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java index 44047b2..030da25 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java @@ -23,7 +23,7 @@ public class TimeService { @EJB DataSetApi dataSetApi; - @Schedule(minute = "*", hour = "*") + @Schedule(minute = "15", hour = "22") public void doWork() { List datafields = dataSetFieldFacade.getAll(); diff --git a/HomeDsBackend/src/main/java/at/htl/web/IndexController.java b/HomeDsBackend/src/main/java/at/htl/web/IndexController.java index f51c690..aca07a2 100644 --- a/HomeDsBackend/src/main/java/at/htl/web/IndexController.java +++ b/HomeDsBackend/src/main/java/at/htl/web/IndexController.java @@ -22,7 +22,7 @@ public class IndexController { private static LocalDateTime lastOnline; public boolean isServerOnline() { - if (cnt == 0 || (lastOnline.plusMinutes(2).isBefore(LocalDateTime.now()))) { + if (cnt == 0 || (lastOnline.plusSeconds(30).isBefore(LocalDateTime.now()))) { try { cnt++; on = true; diff --git a/HomeDsBackend/src/main/java/at/htl/web/MediaController.java b/HomeDsBackend/src/main/java/at/htl/web/MediaController.java index be0c066..addec18 100644 --- a/HomeDsBackend/src/main/java/at/htl/web/MediaController.java +++ b/HomeDsBackend/src/main/java/at/htl/web/MediaController.java @@ -4,6 +4,11 @@ import at.htl.model.Media; import at.htl.utils.LayoutChangerUtil; import at.htl.xiboClient.MediaApi; +import org.primefaces.event.SelectEvent; +import org.primefaces.model.tagcloud.DefaultTagCloudItem; +import org.primefaces.model.tagcloud.DefaultTagCloudModel; +import org.primefaces.model.tagcloud.TagCloudItem; +import org.primefaces.model.tagcloud.TagCloudModel; import javax.annotation.PostConstruct; import javax.enterprise.inject.Model; @@ -12,6 +17,7 @@ import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable; +import java.time.LocalDateTime; import java.util.List; @Model @@ -24,27 +30,46 @@ public class MediaController implements Serializable { @Inject LayoutChangerUtil layoutChangerUtil; + private TagCloudModel model; + + private String tags; + private static List medias; private static List shortMedias; + private static LocalDateTime lastOnline; + @PostConstruct public void init() { + tags = ""; try { - if (medias != null) { + if (medias != null && lastOnline.isAfter(LocalDateTime.now())) { //no need for update } else { - this.updateList(); + this.updateList(tags); + lastOnline = LocalDateTime.now().plusMinutes(5); } } catch (NoConnectionException e) { e.printStackTrace(); } + model = new DefaultTagCloudModel(); + model.addTag(new DefaultTagCloudItem("Informatik", 5)); + model.addTag(new DefaultTagCloudItem("Medientechnik", 1)); + model.addTag(new DefaultTagCloudItem("Biomedizin", 1)); + model.addTag(new DefaultTagCloudItem("Elektronik", 1)); + model.addTag(new DefaultTagCloudItem("Projekte", 4)); + model.addTag(new DefaultTagCloudItem("Projektvideos", "#", 2)); } - private void updateList() throws NoConnectionException { - this.medias = mediaApi.getAllMedia(0,300); - shortMedias = medias.subList(0,5); + private void updateList(String cloudTags) throws NoConnectionException { + this.medias = mediaApi.getAllMedia(0,50, cloudTags); + if (medias.size()>10) + shortMedias = medias.subList(0,5); + else { + shortMedias = medias; + } } public void playMedia(long mediaId) { @@ -70,6 +95,24 @@ public void playMedia(long mediaId) { } } + public void onSelect(SelectEvent event) { + TagCloudItem item = (TagCloudItem) event.getObject(); + FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item Selected", item.getLabel()); + + //bec of starting not with , + if (tags.isEmpty()) + tags = item.getLabel(); + else + tags += ","+item.getLabel(); + + FacesContext.getCurrentInstance().addMessage(null, msg); + try { + mediaApi.getAllMedia(0,100, tags); + } catch (NoConnectionException e) { + e.printStackTrace(); + } + } + //region Getter & Setter public List getMedias() { return medias; @@ -86,5 +129,22 @@ public List getShortMedias() { public void setShortMedias(List shortMedias) { this.shortMedias = shortMedias; } + + public TagCloudModel getModel() { + return model; + } + + public void setModel(TagCloudModel model) { + this.model = model; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + //endregion } diff --git a/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java b/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java index 4d6b6f7..1fa0fcb 100644 --- a/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java +++ b/HomeDsBackend/src/main/java/at/htl/xiboClient/MediaApi.java @@ -15,25 +15,23 @@ import java.net.HttpURLConnection; import java.util.HashMap; import java.util.LinkedList; +import java.util.List; @Stateless public class MediaApi { public final String editPlaylistId = "157"; - public LinkedList getAllMedia(int start, int length) throws NoConnectionException { + public LinkedList getAllMedia(int start, int length, String tags) throws NoConnectionException { BufferedReader in; LinkedList medias = new LinkedList(); Media actual = new Media(); - HashMap params = new HashMap<>(); - params.put("type", "image"); - try { HttpURLConnection con = new RequestHelper() - .executeRequest(RequestTypeEnum.GET, "tags=project", - new RequestHelper().BASE_URL + "api/library?start=" + start +"&length="+length, + .executeRequest(RequestTypeEnum.GET, null, + new RequestHelper().BASE_URL + "api/library?start=" + start +"&length="+length+"&tags="+tags, AuthentificationHandler.getTOKEN()); try { in = new BufferedReader(new InputStreamReader(con.getInputStream())); diff --git a/HomeDsBackend/src/main/webapp/media.xhtml b/HomeDsBackend/src/main/webapp/media.xhtml index ba6583a..66b0bbe 100644 --- a/HomeDsBackend/src/main/webapp/media.xhtml +++ b/HomeDsBackend/src/main/webapp/media.xhtml @@ -6,7 +6,7 @@ xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:b="http://bootsfaces.net/ui" xmlns:ui="http://java.sun.com/jsf/facelets" - xmlns:f="http://xmlns.jcp.org/jsf/core"> + xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:p="http://primefaces.org/ui"> Media Play @@ -48,6 +48,9 @@ + + + From d9112b6492a6000580bf2838dc18e0424df4e2b6 Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Sun, 4 Mar 2018 22:54:25 +0100 Subject: [PATCH 4/8] implemented tagcloud search and designe --- .../main/java/at/htl/web/MediaController.java | 32 ++++++++++--------- HomeDsBackend/src/main/webapp/media.xhtml | 10 +++++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/HomeDsBackend/src/main/java/at/htl/web/MediaController.java b/HomeDsBackend/src/main/java/at/htl/web/MediaController.java index addec18..ff914c2 100644 --- a/HomeDsBackend/src/main/java/at/htl/web/MediaController.java +++ b/HomeDsBackend/src/main/java/at/htl/web/MediaController.java @@ -46,8 +46,7 @@ public void init() { try { if (medias != null && lastOnline.isAfter(LocalDateTime.now())) { //no need for update - } - else { + } else { this.updateList(tags); lastOnline = LocalDateTime.now().plusMinutes(5); } @@ -64,14 +63,23 @@ public void init() { } private void updateList(String cloudTags) throws NoConnectionException { - this.medias = mediaApi.getAllMedia(0,50, cloudTags); - if (medias.size()>10) - shortMedias = medias.subList(0,5); + this.medias = mediaApi.getAllMedia(0, 50, cloudTags); + if (medias.size() > 10) + shortMedias = medias.subList(0, 5); else { shortMedias = medias; } } + public void clearCloud() { + tags = ""; + try { + this.updateList(tags); + } catch (NoConnectionException e) { + e.printStackTrace(); + } + } + public void playMedia(long mediaId) { FacesContext context = FacesContext.getCurrentInstance(); try { @@ -81,12 +89,10 @@ public void playMedia(long mediaId) { if (mediaApi.editWidget(mediaId) == 200) { layoutChangerUtil.changeLayoutForAll(39); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Succesfully set media to playlist")); - } - else { + } else { context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Error while playing medi")); } - } - else { + } else { context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Error while removing media from playlist")); } } @@ -99,15 +105,11 @@ public void onSelect(SelectEvent event) { TagCloudItem item = (TagCloudItem) event.getObject(); FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item Selected", item.getLabel()); - //bec of starting not with , - if (tags.isEmpty()) - tags = item.getLabel(); - else - tags += ","+item.getLabel(); + tags = item.getLabel(); FacesContext.getCurrentInstance().addMessage(null, msg); try { - mediaApi.getAllMedia(0,100, tags); + this.updateList(tags); } catch (NoConnectionException e) { e.printStackTrace(); } diff --git a/HomeDsBackend/src/main/webapp/media.xhtml b/HomeDsBackend/src/main/webapp/media.xhtml index 66b0bbe..fe3945d 100644 --- a/HomeDsBackend/src/main/webapp/media.xhtml +++ b/HomeDsBackend/src/main/webapp/media.xhtml @@ -48,7 +48,9 @@ - + + + @@ -69,6 +71,12 @@ + From dae0584e5148a982b36939449fc41d49102fc3ab Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Mon, 5 Mar 2018 00:03:20 +0100 Subject: [PATCH 5/8] added campaigns --- .../java/at/htl/facades/CampaignFacade.java | 36 +++++++++++++++ .../src/main/java/at/htl/model/Campaign.java | 46 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java create mode 100644 HomeDsBackend/src/main/java/at/htl/model/Campaign.java diff --git a/HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java b/HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java new file mode 100644 index 0000000..acd5581 --- /dev/null +++ b/HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java @@ -0,0 +1,36 @@ +package at.htl.facades; + +import at.htl.model.Campaign; +import at.htl.model.DataSetDataField; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; +import java.util.List; + +public class CampaignFacade { + + @PersistenceContext + EntityManager entityManager; + + public void save(Campaign campaign) { + entityManager.persist(campaign); + } + + public void merge(Campaign campaign) { + entityManager.merge(campaign); + } + + public Campaign findById(long id) { + return entityManager.find(Campaign.class,id); + } + + public List getAll() { + TypedQuery query = entityManager.createNamedQuery("Campaign.GetAll",Campaign.class); + return query.getResultList(); + } + + public void delete(long id) { + entityManager.remove(findById(id)); + } +} diff --git a/HomeDsBackend/src/main/java/at/htl/model/Campaign.java b/HomeDsBackend/src/main/java/at/htl/model/Campaign.java new file mode 100644 index 0000000..7828af2 --- /dev/null +++ b/HomeDsBackend/src/main/java/at/htl/model/Campaign.java @@ -0,0 +1,46 @@ +package at.htl.model; + +import javax.persistence.*; + +@NamedQueries( + { + @NamedQuery(name = "Campaign.GetAll", + query = "select d from Campaign d") + }) + +@Table +@Entity +public class Campaign { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private long campaignId; + + public Campaign(long campaignId) { + this.campaignId = campaignId; + } + + public Campaign() { } + + //region Getter & Setter + + public long getCampaignId() { + return campaignId; + } + + public void setCampaignId(long campaignId) { + this.campaignId = campaignId; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + //endregion +} From 10eedf9ddc3fc5a1ea6970e296b89f2187539f1a Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Mon, 5 Mar 2018 00:03:48 +0100 Subject: [PATCH 6/8] added dataSet function for new layout changing logic --- .../src/main/java/at/htl/facades/DataSetFieldFacade.java | 6 +++++- .../src/main/java/at/htl/model/DataSetDataField.java | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/HomeDsBackend/src/main/java/at/htl/facades/DataSetFieldFacade.java b/HomeDsBackend/src/main/java/at/htl/facades/DataSetFieldFacade.java index 2c32489..961da36 100644 --- a/HomeDsBackend/src/main/java/at/htl/facades/DataSetFieldFacade.java +++ b/HomeDsBackend/src/main/java/at/htl/facades/DataSetFieldFacade.java @@ -37,7 +37,6 @@ public DataSetDataField findById(long id) { return entityManager.find(DataSetDataField.class, id); } - public List getAll() { TypedQuery q = entityManager.createNamedQuery("DataSetDataField.GetAll", DataSetDataField.class); return q.getResultList(); @@ -54,4 +53,9 @@ public void deleteById(long id) { DataSetDataField entityToDelete = findById(id); entityManager.remove(entityToDelete); } + + public List getActiveDataSetRows() { + TypedQuery q = entityManager.createNamedQuery("DataSetDataField.findActive", DataSetDataField.class); + return q.getResultList(); + } } diff --git a/HomeDsBackend/src/main/java/at/htl/model/DataSetDataField.java b/HomeDsBackend/src/main/java/at/htl/model/DataSetDataField.java index 1f3544f..ebceb41 100644 --- a/HomeDsBackend/src/main/java/at/htl/model/DataSetDataField.java +++ b/HomeDsBackend/src/main/java/at/htl/model/DataSetDataField.java @@ -11,7 +11,10 @@ query = "select d from DataSetDataField d"), @NamedQuery(name = "DataSetDataField.findByRowId", - query = "select d from DataSetDataField d where :id = d.dataRowId") + query = "select d from DataSetDataField d where :id = d.dataRowId"), + + @NamedQuery(name = "DataSetDataField.findActive", + query = "select d from DataSetDataField d where d.isActive = true") }) @Table From 330b27c47e00c2587609d742831a9aca22d52d5d Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Mon, 5 Mar 2018 00:04:18 +0100 Subject: [PATCH 7/8] change layout logic for timed actions added and refactored schedule lgo --- .../java/at/htl/utils/LayoutChangerUtil.java | 41 ++++++++++++++----- .../main/java/at/htl/utils/TimeService.java | 17 +++++++- .../main/java/at/htl/web/MediaController.java | 8 ++-- .../java/at/htl/xiboClient/DisplayApi.java | 35 ++++++++-------- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java index c426e91..b19faab 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java @@ -1,7 +1,11 @@ package at.htl.utils; import at.htl.exceptions.NoConnectionException; +import at.htl.facades.CampaignFacade; +import at.htl.facades.DataSetFieldFacade; +import at.htl.model.Campaign; import at.htl.model.DataSet; +import at.htl.model.DataSetDataField; import at.htl.model.Display; import at.htl.xiboClient.DataSetApi; import at.htl.xiboClient.DisplayApi; @@ -10,6 +14,7 @@ import javax.inject.Inject; import java.time.LocalDateTime; import java.util.LinkedList; +import java.util.List; @Stateless public class LayoutChangerUtil { @@ -20,18 +25,34 @@ public class LayoutChangerUtil { @Inject DataSetApi dataSetApi; - public void changeLayoutForAll(int layoutId) { - try { - LinkedList displays = displayApi.GetAllDisplays(); + @Inject + DataSetFieldFacade dataSetFieldFacade; + + @Inject + CampaignFacade campaignFacade; - /*for (int i = 0; i < displays.size(); i++) { - displayApi.ChangeLayout(displays.get(i).getDisplayGroupId(), layoutId); - }*/ - displayApi.ScheduleLayout(LocalDateTime.now(),LocalDateTime.now().plusMinutes(2)); + public void changeLayout(long campaignLayoutId,LocalDateTime toDate) throws NoConnectionException { + displayApi.ScheduleLayout(campaignLayoutId, LocalDateTime.now(),toDate); dataSetApi.collectNowAll(); - } catch (NoConnectionException e) { - e.printStackTrace(); - } + } + /* + Wenn keine DataSets verfügbar Layout auf normal wechseln (alte kampagne löschen) + Wenn DataSets verfügbar sind dataset layout einlegen (neue kampagne anlegen) + */ + public void campaignLogic() { + if (dataSetFieldFacade.getActiveDataSetRows().size()>0) { + try { + long id = -1; + if (campaignFacade.getAll().size() <= 0 && (id = displayApi.ScheduleLayout(43,LocalDateTime.now(), LocalDateTime.MAX)) > 0) { + campaignFacade.save(new Campaign(id)); + } + } catch (NoConnectionException e) { + e.printStackTrace(); + } + } + else { + campaignFacade.delete(campaignFacade.getAll().get(0).getId()); + } } } diff --git a/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java b/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java index 030da25..a8988ab 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java @@ -1,9 +1,12 @@ package at.htl.utils; import at.htl.exceptions.NoConnectionException; +import at.htl.facades.CampaignFacade; import at.htl.facades.DataSetFieldFacade; +import at.htl.model.Campaign; import at.htl.model.DataSetDataField; import at.htl.xiboClient.DataSetApi; +import at.htl.xiboClient.DisplayApi; import javax.annotation.PostConstruct; import javax.ejb.EJB; @@ -11,6 +14,7 @@ import javax.ejb.Singleton; import javax.ejb.Startup; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; @Singleton @@ -23,7 +27,16 @@ public class TimeService { @EJB DataSetApi dataSetApi; - @Schedule(minute = "15", hour = "22") + @EJB + DisplayApi displayApi; + + @EJB + CampaignFacade campaignFacade; + + @EJB + LayoutChangerUtil layoutChangerUtil; + + @Schedule(minute = "*", hour = "23") public void doWork() { List datafields = dataSetFieldFacade.getAll(); @@ -83,6 +96,8 @@ public void doWork() { else { System.out.println("Every min scheduler had no job :(!"); } + + } @PostConstruct diff --git a/HomeDsBackend/src/main/java/at/htl/web/MediaController.java b/HomeDsBackend/src/main/java/at/htl/web/MediaController.java index ff914c2..d825eeb 100644 --- a/HomeDsBackend/src/main/java/at/htl/web/MediaController.java +++ b/HomeDsBackend/src/main/java/at/htl/web/MediaController.java @@ -87,7 +87,7 @@ public void playMedia(long mediaId) { if (widgetId > 0) { if (mediaApi.deleteWidget(widgetId) == 200) { if (mediaApi.editWidget(mediaId) == 200) { - layoutChangerUtil.changeLayoutForAll(39); + layoutChangerUtil.changeLayout(44,LocalDateTime.now().plusMinutes(2)); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Succesfully set media to playlist")); } else { context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Error while playing medi")); @@ -105,11 +105,13 @@ public void onSelect(SelectEvent event) { TagCloudItem item = (TagCloudItem) event.getObject(); FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item Selected", item.getLabel()); - tags = item.getLabel(); FacesContext.getCurrentInstance().addMessage(null, msg); try { - this.updateList(tags); + if (!tags.equals(item.getLabel())) { + tags = item.getLabel(); + this.updateList(tags); + } } catch (NoConnectionException e) { e.printStackTrace(); } diff --git a/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java b/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java index 18050f8..9d6ed8a 100644 --- a/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java +++ b/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java @@ -2,6 +2,7 @@ import at.htl.enums.RequestTypeEnum; import at.htl.exceptions.NoConnectionException; +import at.htl.model.Campaign; import at.htl.model.Display; import at.htl.utils.AuthentificationHandler; import at.htl.utils.RequestHelper; @@ -9,20 +10,14 @@ import org.json.JSONObject; import javax.ejb.Stateless; -import javax.swing.text.DateFormatter; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; -import java.text.SimpleDateFormat; -import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.LinkedList; -import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME; - @Stateless public class DisplayApi { @@ -76,36 +71,42 @@ public LinkedList GetAllDisplays() throws NoConnectionException { return displays; } - public void ScheduleLayout(LocalDateTime fromDate, LocalDateTime toDate) throws NoConnectionException { + public long ScheduleLayout(long campaingLayoutId, LocalDateTime fromDate, LocalDateTime toDate) throws NoConnectionException { + Campaign act = new Campaign(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); BufferedReader in; LinkedList displays = new LinkedList<>(); - Display act = new Display(); try { //Get all Datasets HttpURLConnection con = new RequestHelper() .executeRequest(RequestTypeEnum.POST, - "eventTypeId=1&campaignId=" + 44 + + "eventTypeId=1&campaignId=" + campaingLayoutId + "&displayOrder=0&isPriority=11&displayGroupIds[]="+14+"&fromDt="+fromDate.format(formatter)+"&toDt="+toDate.format(formatter), new RequestHelper().BASE_URL + "api/schedule", AuthentificationHandler.getTOKEN()); - in = new BufferedReader(new InputStreamReader(con.getInputStream())); + if (con.getResponseCode()==201) { + in = new BufferedReader(new InputStreamReader(con.getInputStream())); - String output; - StringBuffer response = new StringBuffer(); - while ((output = in.readLine()) != null) - { - response.append(output); + String output; + StringBuffer response = new StringBuffer(); + while ((output = in.readLine()) != null) { + response.append(output); + } + + JSONObject jsonObject = new JSONObject(response); + return jsonObject.getLong("campaignId"); + } + else { + return -1; } } catch (NullPointerException ex) { throw new NoConnectionException("Es ist kein Response vorhanden", ex); } catch (IOException e) { - e.printStackTrace(); + throw new NoConnectionException("IO Exception", e); } - } } From bf3a12f0f2206d688747ffbb5f4ae6f2d1c48507 Mon Sep 17 00:00:00 2001 From: SakalAndrej Date: Mon, 5 Mar 2018 01:11:31 +0100 Subject: [PATCH 8/8] implemented change layout when dataset is avail --- .../java/at/htl/facades/CampaignFacade.java | 2 ++ .../java/at/htl/utils/LayoutChangerUtil.java | 32 +++++++++++-------- .../main/java/at/htl/utils/TimeService.java | 1 + .../java/at/htl/web/DataSetController.java | 7 ++++ .../java/at/htl/xiboClient/DisplayApi.java | 32 +++++++++++++------ .../main/resources/META-INF/persistence.xml | 15 +++++---- 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java b/HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java index acd5581..9945932 100644 --- a/HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java +++ b/HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java @@ -3,11 +3,13 @@ import at.htl.model.Campaign; import at.htl.model.DataSetDataField; +import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.TypedQuery; import java.util.List; +@Stateless public class CampaignFacade { @PersistenceContext diff --git a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java index b19faab..b1f2b6f 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java @@ -4,17 +4,12 @@ import at.htl.facades.CampaignFacade; import at.htl.facades.DataSetFieldFacade; import at.htl.model.Campaign; -import at.htl.model.DataSet; -import at.htl.model.DataSetDataField; -import at.htl.model.Display; import at.htl.xiboClient.DataSetApi; import at.htl.xiboClient.DisplayApi; import javax.ejb.Stateless; import javax.inject.Inject; import java.time.LocalDateTime; -import java.util.LinkedList; -import java.util.List; @Stateless public class LayoutChangerUtil { @@ -31,28 +26,37 @@ public class LayoutChangerUtil { @Inject CampaignFacade campaignFacade; - public void changeLayout(long campaignLayoutId,LocalDateTime toDate) throws NoConnectionException { - displayApi.ScheduleLayout(campaignLayoutId, LocalDateTime.now(),toDate); - dataSetApi.collectNowAll(); + public void changeLayout(long campaignLayoutId, LocalDateTime toDate) throws NoConnectionException { + displayApi.scheduleLayout(campaignLayoutId, LocalDateTime.now(), toDate); + dataSetApi.collectNowAll(); } /* - Wenn keine DataSets verfügbar Layout auf normal wechseln (alte kampagne löschen) + Wenn keine DataSets verfügbar Layout auf normal wechseln (alte kampagne löschen falls es eine alte gibt wenn nicht nichts tun) Wenn DataSets verfügbar sind dataset layout einlegen (neue kampagne anlegen) */ public void campaignLogic() { - if (dataSetFieldFacade.getActiveDataSetRows().size()>0) { + if (dataSetFieldFacade.getActiveDataSetRows().size() > 0) { try { long id = -1; - if (campaignFacade.getAll().size() <= 0 && (id = displayApi.ScheduleLayout(43,LocalDateTime.now(), LocalDateTime.MAX)) > 0) { + if (campaignFacade.getAll().size() <= 0 && (id = displayApi.scheduleLayout(43, LocalDateTime.now(), LocalDateTime.now().plusMinutes(2))) > 0) { campaignFacade.save(new Campaign(id)); } } catch (NoConnectionException e) { e.printStackTrace(); } - } - else { - campaignFacade.delete(campaignFacade.getAll().get(0).getId()); + } else { + if (campaignFacade.getAll() != null && campaignFacade.getAll().size()>0) { + long deleteId = campaignFacade.getAll().get(0).getId(); + + try { + if (displayApi.deleteEvent(campaignFacade.getAll().get(0).getCampaignId())) { + campaignFacade.delete(deleteId); + } + } catch (NoConnectionException e) { + e.printStackTrace(); + } + } } } } diff --git a/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java b/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java index a8988ab..45db19d 100644 --- a/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java +++ b/HomeDsBackend/src/main/java/at/htl/utils/TimeService.java @@ -97,6 +97,7 @@ public void doWork() { System.out.println("Every min scheduler had no job :(!"); } + layoutChangerUtil.campaignLogic(); } diff --git a/HomeDsBackend/src/main/java/at/htl/web/DataSetController.java b/HomeDsBackend/src/main/java/at/htl/web/DataSetController.java index 211c259..c1be869 100644 --- a/HomeDsBackend/src/main/java/at/htl/web/DataSetController.java +++ b/HomeDsBackend/src/main/java/at/htl/web/DataSetController.java @@ -3,6 +3,7 @@ import at.htl.exceptions.NoConnectionException; import at.htl.facades.DataSetFieldFacade; import at.htl.model.DataSetDataField; +import at.htl.utils.LayoutChangerUtil; import at.htl.xiboClient.DataSetApi; import javax.annotation.PostConstruct; @@ -25,6 +26,9 @@ public class DataSetController implements Serializable { @Inject DataSetApi dataSetApi; + @Inject + LayoutChangerUtil layoutChangerUtil; + private static List dataSetData; private DataSetDataField dataSetToAdd; @@ -37,6 +41,7 @@ public DataSetController() { public void init() { this.updateList(); dataSetToAdd = new DataSetDataField(); + //layoutChangerUtil.campaignLogic(); } public void removeDataSet(DataSetDataField dataSet) { @@ -60,6 +65,7 @@ public void removeDataSet(DataSetDataField dataSet) { } catch (NoConnectionException ex) { context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "", "Error while establishing a connection")); } + layoutChangerUtil.campaignLogic(); } public void addDataSet() { @@ -87,6 +93,7 @@ public void addDataSetToXibo(DataSetDataField dataFieldToAdd) { dataFieldToAdd.setDataRowId(id); dataSetFieldFacade.save(dataFieldToAdd); this.updateList(); + layoutChangerUtil.campaignLogic(); //clear add variable dataSetToAdd = new DataSetDataField(); diff --git a/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java b/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java index 9d6ed8a..b903f7e 100644 --- a/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java +++ b/HomeDsBackend/src/main/java/at/htl/xiboClient/DisplayApi.java @@ -2,7 +2,6 @@ import at.htl.enums.RequestTypeEnum; import at.htl.exceptions.NoConnectionException; -import at.htl.model.Campaign; import at.htl.model.Display; import at.htl.utils.AuthentificationHandler; import at.htl.utils.RequestHelper; @@ -21,7 +20,7 @@ @Stateless public class DisplayApi { - public LinkedList GetAllDisplays() throws NoConnectionException { + public LinkedList getAllDisplays() throws NoConnectionException { BufferedReader in; LinkedList displays = new LinkedList<>(); Display act = new Display(); @@ -71,19 +70,17 @@ public LinkedList GetAllDisplays() throws NoConnectionException { return displays; } - public long ScheduleLayout(long campaingLayoutId, LocalDateTime fromDate, LocalDateTime toDate) throws NoConnectionException { + public long scheduleLayout(long campaingLayoutId, LocalDateTime fromDate, LocalDateTime toDate) throws NoConnectionException { - Campaign act = new Campaign(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); BufferedReader in; - LinkedList displays = new LinkedList<>(); try { //Get all Datasets HttpURLConnection con = new RequestHelper() .executeRequest(RequestTypeEnum.POST, "eventTypeId=1&campaignId=" + campaingLayoutId + - "&displayOrder=0&isPriority=11&displayGroupIds[]="+14+"&fromDt="+fromDate.format(formatter)+"&toDt="+toDate.format(formatter), + "&displayOrder=0&isPriority=11&displayGroupIds[]="+14+"&fromDt="+fromDate.format(formatter)+"&toDt="+toDate.format(formatter)+"&syncTimezone=1", new RequestHelper().BASE_URL + "api/schedule", AuthentificationHandler.getTOKEN()); @@ -95,8 +92,7 @@ public long ScheduleLayout(long campaingLayoutId, LocalDateTime fromDate, LocalD while ((output = in.readLine()) != null) { response.append(output); } - - JSONObject jsonObject = new JSONObject(response); + JSONObject jsonObject = new JSONObject(response.toString()); return jsonObject.getLong("campaignId"); } else { @@ -109,4 +105,22 @@ public long ScheduleLayout(long campaingLayoutId, LocalDateTime fromDate, LocalD } } + public boolean deleteEvent(long campaignId) throws NoConnectionException { + try { + HttpURLConnection con = new RequestHelper() + .executeRequest(RequestTypeEnum.DELETE, null, + new RequestHelper().BASE_URL + "api/schedule/" + campaignId, + AuthentificationHandler.getTOKEN()); + if (con.getResponseCode()==204) { + return true; + } + else { + return false; + } + } catch (NullPointerException ex) { + throw new NoConnectionException("Es ist kein Response vorhanden", ex); + } catch (IOException e) { + throw new NoConnectionException("IO Exception", e); + } + } } diff --git a/HomeDsBackend/src/main/resources/META-INF/persistence.xml b/HomeDsBackend/src/main/resources/META-INF/persistence.xml index 8f139e7..e1cacff 100644 --- a/HomeDsBackend/src/main/resources/META-INF/persistence.xml +++ b/HomeDsBackend/src/main/resources/META-INF/persistence.xml @@ -4,14 +4,15 @@ java:/mysql - +