...
 
Commits (8)
......@@ -82,6 +82,8 @@ public class ControlServer extends Application
router.attach("/testresultdetail", TestResultDetailResource.class);
router.attach("/sync", SyncResource.class);
router.attach("/sync/clients/{sync_group_uid}", SyncGroupClientsResource.class);
router.attach("/settings", SettingsResource.class);
// collection of UserAgent etc.for IE (via server)
......
/*******************************************************************************
* Copyright 2013-2014 alladin-IT GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package at.alladin.rmbt.controlServer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import at.alladin.rmbt.shared.ErrorList;
public class SyncGroupClientsResource extends ServerResource {
@Post("json")
public String request(final String entity) {
addAllowOrigin();
final ErrorList errorList = new ErrorList();
final JSONObject answer = new JSONObject();
int syncGroupUID = -1;
try {
String param = getRequest().getAttributes().get("sync_group_uid").toString();
syncGroupUID = Integer.parseInt(param);
}
catch (NullPointerException | NumberFormatException e) {
errorList.addError("ERROR_SYNC_GROUP_CLIENTS_FORMAT");
}
if (entity != null && !entity.isEmpty()) {
try {
JSONObject request = new JSONObject(entity);
final String lang = request.optString("client_language");
final List<String> langs = Arrays.asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));
if (langs.contains(lang)) {
errorList.setLanguage(lang);
}
} catch (Exception e) {
e.printStackTrace();
//Ignore it
}
}
if(conn != null) {
try {
//Select client uid, uuid, sync_code and client_type_name.
PreparedStatement statement = conn.prepareStatement(
"SELECT C.uid, C.uuid, C.sync_code, CT.name as client_type_name " +
"FROM client C " +
"INNER JOIN client_type CT ON CT.uid = C.client_type_id " +
"WHERE C.sync_group_id = ?"
);
statement.setInt(1, syncGroupUID);
ResultSet resultSet = statement.executeQuery();
//Array to save clients from query.
JSONArray clientsArray = new JSONArray();
while (resultSet.next()) {
JSONObject clientObject = new JSONObject();
clientObject.put("uid", resultSet.getInt("uid"));
clientObject.putOpt("uuid", resultSet.getString("uuid"));
clientObject.putOpt("sync_code", resultSet.getString("sync_code"));
clientObject.putOpt("client_type_name", resultSet.getString("client_type_name"));
clientsArray.put(clientObject);
}
if(clientsArray.length() == 0) errorList.addError("ERROR_SYNC_GROUP_CLIENTS_NOT_FOUND");
answer.put("clients", clientsArray);
} catch (SQLException e) {
e.printStackTrace();
}
} else { //No DB Connection
errorList.addError("ERROR_DB_CONNECTION");
}
try {
answer.putOpt("error", errorList.getList());
}
catch (final JSONException e) {
System.out.println("Error saving ErrorList!");
e.printStackTrace();
}
return answer.toString();
}
@Get("json")
public String retrieve(final String entity)
{
return request(entity);
}
}
......@@ -166,6 +166,9 @@ ERROR_DB_UPDATE_SYNC_GROUP = Could not update sync group from client in databas
ERROR_DB_DELETE_SYNC_GROUP = Could not delete sync group from database.
ERROR_DB_STORE_STATUS = Could not insert status in database.
ERROR_SYNC_GROUP_CLIENTS_NOT_FOUND = Could not find sync group with provided uid or the sync group is empty.
ERROR_SYNC_GROUP_CLIENTS_FORMAT = Wrong format of the provided sync group uid.
ERROR_DB_QOS_GET_OBJECTIVE_NOT_FOUND = Could not find qos test objectives
ERROR_LOG_WRITE = Error while writing log file
......
......@@ -135,6 +135,9 @@ ERROR_DB_DELETE_SYNC_GROUP = Nemohu smazat synchronizační skupinu z datbáze.
ERROR_DB_QOS_GET_OBJECTIVE_NOT_FOUND = Nemohu najít cíle testu QoS
ERROR_SYNC_GROUP_CLIENTS_NOT_FOUND = Nemohu nalézt synchronizační skupiny s poskytnutám uid nebo je skupina prázdná.
ERROR_SYNC_GROUP_CLIENTS_FORMAT = Špatný formát poskytnutého uid synchronizační skupiny.
# detail keys
key_time = Čas testu
......
......@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-4.1-all.zip
......@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-4.1-all.zip
......@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-4.1-all.zip