Skip to content

Commit

Permalink
Merge pull request #36 from SakalAndrej/develop
Browse files Browse the repository at this point in the history
Major Update
  • Loading branch information
SakalAndrej authored Mar 4, 2018
2 parents 8333132 + ce48eea commit 7e6df49
Show file tree
Hide file tree
Showing 30 changed files with 162 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public HttpURLConnection executeRequest(RequestTypeEnum executeType, String para
obj = new URL(url);
con = (HttpURLConnection) obj.openConnection();
con.setRequestProperty("Authorization", "Bearer " + TOKEN);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
switch (executeType) {
case GET:
con.setRequestMethod("GET");
Expand Down
11 changes: 1 addition & 10 deletions HomeDsBackend/src/main/java/at/htl/utils/TimeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,9 @@ public void doWork() {
}
}

@Schedule(hour = "20", minute = "10")
public void doSomething() {
System.out.println("hour triggered");
}

public TimeService() {
System.out.println("Hello one minute");
}

@PostConstruct
public void init() {
System.out.println("something");
AuthentificationHandler.Authenticate();
}


Expand Down
15 changes: 6 additions & 9 deletions HomeDsBackend/src/main/java/at/htl/web/CrawlController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ public class CrawlController implements Serializable {

private String collapsed;

private CrawlController() {
}
private CrawlController() { }

@PostConstruct
public void init() {
this.startCrawl();
actLayoutId = -1;
this.startCrawl();
}

public void startCrawl() {
Expand All @@ -54,22 +53,20 @@ public void startCrawl() {
formatterUrl = "\'http://localhost:8080/homeds/rs/crawler" + query + "\'";
crawl = crawler.getLayoutsWithAllSubEntities(actLayoutId, name);

if (!crawl.isEmpty() && crawl.length()>2) {
if (!crawl.isEmpty() && crawl.length() > 2) {
crawl = new JSONArray(crawl).toString();
collapsed = "false";
}
else
} else
collapsed = "true";
}

public void startedCrawlGrowl() {
FacesContext context = FacesContext.getCurrentInstance();
startCrawl();

if (!crawl.isEmpty() && crawl.length()>2) {
if (!crawl.isEmpty() && crawl.length() > 2) {
context.addMessage(null, new FacesMessage("Successful"));
}
else {
} else {
context.addMessage(null, new FacesMessage("No Content"));
}
}
Expand Down
33 changes: 29 additions & 4 deletions HomeDsBackend/src/main/java/at/htl/web/DataSetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DataSetController implements Serializable {
@Inject
DataSetApi dataSetApi;

private List<DataSetDataField> dataSetData;
private static List<DataSetDataField> dataSetData;

private DataSetDataField dataSetToAdd;

Expand Down Expand Up @@ -105,8 +105,35 @@ public void editDataSet(DataSetDataField dataSetFieldToEdit) {
FacesContext context = FacesContext.getCurrentInstance();
if (dataSetFieldToEdit != null && dataSetFieldToEdit.getValue().isEmpty() == false && dataSetFieldToEdit.getTitle().isEmpty() == false) {

if (dataSetFieldToEdit.getFromDate() != null) {
// when the fromdate is null then...
if (dataSetFieldToEdit.getFromDate()==null) {

// when its active just edit no database delete
if (dataSetFieldToEdit.getDataRowId()>1) {
try {
if (dataSetApi.editDataSetField(dataSetFieldToEdit.getDataSetId(), dataSetFieldToEdit.getDataRowId(), 8, dataSetFieldToEdit.getTitle()) == 200 && this.dataSetApi.editDataSetField(dataSetFieldToEdit.getDataSetId(), dataSetFieldToEdit.getDataRowId(), 9, dataSetFieldToEdit.getValue()) == 200) {
dataSetFieldFacade.merge(dataSetFieldToEdit);
this.updateList();

dataSetApi.collectNowAll();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", String.format("Succesfully edited DataSetRow: " + dataSetFieldToEdit.getDataRowId())));
} else {
this.updateList();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "Error while editing DataSetRow: " + dataSetFieldToEdit.getDataRowId()));
}
} catch (NoConnectionException e) {
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "", "Error while establishing a connection"));
}
}
else {
// when its not active make it active
DataSetDataField temp = dataSetFieldToEdit;
dataSetFieldFacade.deleteById(dataSetFieldToEdit.getId());
temp.setId(0);
this.addDataSetToXibo(temp);
}
}
else {
// editing from date so that it should be active
if (dataSetFieldToEdit.getFromDate().isBefore(LocalDate.now().plusDays(1)) && dataSetFieldToEdit.isActive() == false) {

Expand All @@ -127,8 +154,6 @@ else if ((dataSetFieldToEdit.getDataRowId() < 0 || dataSetFieldToEdit.isActive()
else if (dataSetFieldToEdit.isActive() && dataSetFieldToEdit.getFromDate().isBefore(LocalDate.now().plusDays(1))) {
try {
if (dataSetApi.editDataSetField(dataSetFieldToEdit.getDataSetId(), dataSetFieldToEdit.getDataRowId(), 8, dataSetFieldToEdit.getTitle()) == 200 && this.dataSetApi.editDataSetField(dataSetFieldToEdit.getDataSetId(), dataSetFieldToEdit.getDataRowId(), 9, dataSetFieldToEdit.getValue()) == 200) {
//dataSetFieldFacade.deleteByRowId(dataSetFieldToEdit.getDataRowId());
//dataSetFieldFacade.save(dataSetFieldToEdit);
dataSetFieldFacade.merge(dataSetFieldToEdit);
this.updateList();

Expand Down
52 changes: 22 additions & 30 deletions HomeDsBackend/src/main/java/at/htl/web/IndexController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package at.htl.web;

import at.htl.exceptions.NoConnectionException;
import at.htl.model.Display;
import at.htl.xiboClient.DisplayApi;
import at.htl.xiboClient.StatusApi;

import javax.annotation.PostConstruct;
import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.time.LocalDateTime;

@Model
@Named
Expand All @@ -18,32 +15,27 @@ public class IndexController {
@Inject
StatusApi statusApi;

@Inject
DisplayApi displayApi;

private boolean isOnline = false;

@PostConstruct
public void init() {
try {
displayApi.GetAllDisplays();
} catch (NoConnectionException e) {
e.printStackTrace();
private static boolean on;

private static int cnt = 0;

private static LocalDateTime lastOnline;

public boolean isServerOnline() {
if (cnt == 0 || (lastOnline.plusMinutes(2).isBefore(LocalDateTime.now()))) {
try {
cnt++;
on = true;
lastOnline = LocalDateTime.now();
return statusApi.getIsOnline();
} catch (NoConnectionException e) {
cnt++;
on = false;
lastOnline = LocalDateTime.now();
return false;
}
} else {
return on;
}
}

//region Getter & Setter
public boolean isOnline() {
try {
return statusApi.getIsOnline();
} catch (NoConnectionException e) {
return false;
}
}

public void setOnline(boolean online) {
isOnline = online;
}
//endregion

}
11 changes: 8 additions & 3 deletions HomeDsBackend/src/main/java/at/htl/web/MediaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ public class MediaController implements Serializable {
@Inject
LayoutChangerUtil layoutChangerUtil;

private List<Media> medias;
private static List<Media> medias;

private List<Media> shortMedias;
private static List<Media> shortMedias;

@PostConstruct
public void init() {
try {
this.updateList();
if (medias != null) {
//no need for update
}
else {
this.updateList();
}
} catch (NoConnectionException e) {
e.printStackTrace();
}
Expand Down
16 changes: 15 additions & 1 deletion HomeDsBackend/src/main/java/at/htl/xiboClient/DataSetApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,14 @@ public long getIdForColumnName(long dataSetId, String columnName) throws NoConne

public long editDataSetField(long dataSetId, long dataSetDataId, long dataSetColumnId, String dataSetFieldValue) throws NoConnectionException {



try {

//Get all Datasets
HttpURLConnection con = new RequestHelper()
.executeRequest(RequestTypeEnum.PUT,
"dataSetColumnId_"+dataSetColumnId+"="+dataSetFieldValue,
"dataSetColumnId_"+dataSetColumnId+"="+replaceCodings(dataSetFieldValue),
new RequestHelper().BASE_URL + "api/dataset/data/" + dataSetId+"/"+dataSetDataId,
AuthentificationHandler.getTOKEN());

Expand All @@ -213,6 +215,18 @@ public long editDataSetField(long dataSetId, long dataSetDataId, long dataSetCol
return -1;
}

private String replaceCodings(String dataSetFieldValue) {
String finalValue = dataSetFieldValue.replaceAll("Ä","&Auml;")
.replaceAll("ä","&auml;")
.replaceAll("Ö","&Ouml;")
.replaceAll("ö","&ouml;")
.replaceAll("Ü","&Uuml;")
.replaceAll("ü","&uuml;")
.replaceAll("ß","&szlig")
.replaceAll("&","%26");
return finalValue;
}

public long addDataSetField(DataSetDataField dataField) throws NoConnectionException {
try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import at.htl.enums.RequestTypeEnum;
import at.htl.exceptions.NoConnectionException;
import at.htl.model.DataSet;
import at.htl.model.Display;
import at.htl.utils.AuthentificationHandler;
import at.htl.utils.RequestHelper;
Expand Down Expand Up @@ -44,7 +43,6 @@ public LinkedList<Display> GetAllDisplays() throws NoConnectionException {
}

JSONArray jsonarray = new JSONArray(response.toString());
System.out.println(response.toString());

for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonObject = jsonarray.getJSONObject(i);
Expand Down Expand Up @@ -78,7 +76,7 @@ public void ChangeLayout(long displayGroupId, int layoutId) throws NoConnectionE
//Get all Datasets
HttpURLConnection con = new RequestHelper()
.executeRequest(RequestTypeEnum.POST,
"layoutId=" + 39,
"layoutId=" + 21,
new RequestHelper().BASE_URL + "api/displaygroup/" + 14 + "/action/overlayLayout",
AuthentificationHandler.getTOKEN());

Expand Down

This file was deleted.

Loading

0 comments on commit 7e6df49

Please sign in to comment.