...
 
Commits (7)
......@@ -82,6 +82,7 @@ public class ControlServer extends Application
router.attach("/testresultdetail", TestResultDetailResource.class);
router.attach("/sync", SyncResource.class);
router.attach("/desync", DesyncResource.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.JSONException;
import org.json.JSONObject;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.data.Status;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import at.alladin.rmbt.shared.ErrorList;
import at.alladin.rmbt.shared.ResourceManager;
public class DesyncResource extends ServerResource
{
@Post("json")
public String request(final String entity)
{
addAllowOrigin();
final ErrorList errorList = new ErrorList();
final JSONObject answer = new JSONObject();
if (entity != null && !entity.isEmpty())
// try parse the string to a JSON object
try {
JSONObject request = new JSONObject(entity);
//Get language
String lang = request.optString("language");
//Get supported languages
final List<String> langs = Arrays.asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));
//Fallback to default language if language from request is not supported
if (!langs.contains(lang)) {
lang = settings.getString("RMBT_DEFAULT_LANGUAGE");
}
errorList.setLanguage(lang);
labels = ResourceManager.getSysMsgBundle(new Locale(lang));
Iterator<Map.Entry<String, String>> iterator = getCookies().getValuesMap().entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
System.out.println("Entry: " + entry.getKey() + " : " + entry.getValue());
}
if (conn != null) {
UUID uuid = null;
if (request.optString("uuid").length() > 0) {
uuid = UUID.fromString(request.getString("uuid"));
}
try {
final PreparedStatement statement = conn.prepareStatement(
"UPDATE client " +
"SET sync_group_id = NULL " +
"WHERE uuid = CAST (? AS UUID)"
);
statement.setString(1, uuid.toString());
statement.executeUpdate();
} catch (SQLException e) {
errorList.addError("ERROR_DB_GENERAL");
setStatus(Status.SERVER_ERROR_INTERNAL);
e.printStackTrace();
}
}
else {
errorList.addError("ERROR_DB_CONNECTION");
setStatus(Status.SERVER_ERROR_INTERNAL);
}
}
catch (final JSONException e)
{
errorList.addError("CLIENT_ERROR_BAD_REQUEST");
System.out.println("Error parsing JSDON Data " + e.toString());
}
else
errorList.addErrorString("Expected request is missing.");
try
{
answer.putOpt("error", errorList.getList());
}
catch (final JSONException e)
{
System.out.println("Error saving ErrorList: " + e.toString());
}
return answer.toString();
}
@Get("json")
public String retrieve(final String entity)
{
return request(entity);
}
}