Skip to content

Commit

Permalink
Merge pull request #37 from SakalAndrej/develop
Browse files Browse the repository at this point in the history
Releaseable
  • Loading branch information
SakalAndrej authored Mar 5, 2018
2 parents 7e6df49 + bf3a12f commit 3c4f049
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 66 deletions.
38 changes: 38 additions & 0 deletions HomeDsBackend/src/main/java/at/htl/facades/CampaignFacade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package at.htl.facades;

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
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<Campaign> getAll() {
TypedQuery<Campaign> query = entityManager.createNamedQuery("Campaign.GetAll",Campaign.class);
return query.getResultList();
}

public void delete(long id) {
entityManager.remove(findById(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public DataSetDataField findById(long id) {
return entityManager.find(DataSetDataField.class, id);
}


public List<DataSetDataField> getAll() {
TypedQuery<DataSetDataField> q = entityManager.createNamedQuery("DataSetDataField.GetAll", DataSetDataField.class);
return q.getResultList();
Expand All @@ -54,4 +53,9 @@ public void deleteById(long id) {
DataSetDataField entityToDelete = findById(id);
entityManager.remove(entityToDelete);
}

public List<DataSetDataField> getActiveDataSetRows() {
TypedQuery<DataSetDataField> q = entityManager.createNamedQuery("DataSetDataField.findActive", DataSetDataField.class);
return q.getResultList();
}
}
46 changes: 46 additions & 0 deletions HomeDsBackend/src/main/java/at/htl/model/Campaign.java
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions HomeDsBackend/src/main/java/at/htl/rest/MediaEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
56 changes: 41 additions & 15 deletions HomeDsBackend/src/main/java/at/htl/utils/LayoutChangerUtil.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package at.htl.utils;

import at.htl.exceptions.NoConnectionException;
import at.htl.model.DataSet;
import at.htl.model.Display;
import at.htl.facades.CampaignFacade;
import at.htl.facades.DataSetFieldFacade;
import at.htl.model.Campaign;
import at.htl.xiboClient.DataSetApi;
import at.htl.xiboClient.DisplayApi;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.LinkedList;
import java.time.LocalDateTime;

@Stateless
public class LayoutChangerUtil {
Expand All @@ -19,18 +20,43 @@ public class LayoutChangerUtil {
@Inject
DataSetApi dataSetApi;

public void changeLayoutForAll(int layoutId) {
try {
LinkedList<Display> displays = displayApi.GetAllDisplays();

/*for (int i = 0; i < displays.size(); i++) {
displayApi.ChangeLayout(displays.get(i).getDisplayGroupId(), layoutId);
}*/
displayApi.ChangeLayout(11,layoutId);
dataSetApi.collectNowAll();
} catch (NoConnectionException e) {
e.printStackTrace();
}
@Inject
DataSetFieldFacade dataSetFieldFacade;

@Inject
CampaignFacade campaignFacade;

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 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) {
try {
long id = -1;
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 {
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();
}
}
}
}
}
8 changes: 4 additions & 4 deletions HomeDsBackend/src/main/java/at/htl/utils/RequestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 17 additions & 1 deletion HomeDsBackend/src/main/java/at/htl/utils/TimeService.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
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;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Singleton
Expand All @@ -23,7 +27,16 @@ public class TimeService {
@EJB
DataSetApi dataSetApi;

@Schedule(minute = "*", hour = "*")
@EJB
DisplayApi displayApi;

@EJB
CampaignFacade campaignFacade;

@EJB
LayoutChangerUtil layoutChangerUtil;

@Schedule(minute = "*", hour = "23")
public void doWork() {
List<DataSetDataField> datafields = dataSetFieldFacade.getAll();

Expand Down Expand Up @@ -83,6 +96,9 @@ public void doWork() {
else {
System.out.println("Every min scheduler had no job :(!");
}

layoutChangerUtil.campaignLogic();

}

@PostConstruct
Expand Down
7 changes: 7 additions & 0 deletions HomeDsBackend/src/main/java/at/htl/web/DataSetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,9 @@ public class DataSetController implements Serializable {
@Inject
DataSetApi dataSetApi;

@Inject
LayoutChangerUtil layoutChangerUtil;

private static List<DataSetDataField> dataSetData;

private DataSetDataField dataSetToAdd;
Expand All @@ -37,6 +41,7 @@ public DataSetController() {
public void init() {
this.updateList();
dataSetToAdd = new DataSetDataField();
//layoutChangerUtil.campaignLogic();
}

public void removeDataSet(DataSetDataField dataSet) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 3c4f049

Please sign in to comment.