Skip to content

Commit

Permalink
For #830 - preparing to implement OSRM v5 API for snap-to-roads, adde…
Browse files Browse the repository at this point in the history
…d new setting - 'MatchServiceType'
  • Loading branch information
vitalidze committed Sep 15, 2016
1 parent a6c77d5 commit 6e43877
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/traccar/web/client/i18n/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,6 @@ String defaultNotificationTemplate(@Select DeviceEventType type,
String allowCommandsOnlyForAdmins();

String defaultPreferences();

String matchServiceType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package org.traccar.web.client.model;

import org.traccar.web.shared.model.ApplicationSettings;
import org.traccar.web.shared.model.PasswordHashMethod;
import org.traccar.web.shared.model.*;

import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.data.shared.LabelProvider;
Expand Down Expand Up @@ -45,4 +44,11 @@ public String getLabel(PasswordHashMethod item) {
return item.getName();
}
}

class MatchServiceTypeLabelProvider implements LabelProvider<MatchServiceType> {
@Override
public String getLabel(MatchServiceType item) {
return item.getName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.traccar.web.client.view;

import com.google.gwt.event.logical.shared.*;
import com.sencha.gxt.cell.core.client.form.ComboBoxCell;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.widget.core.client.form.*;
Expand All @@ -23,7 +24,7 @@
import org.traccar.web.client.model.ApplicationSettingsProperties;
import org.traccar.web.client.model.EnumKeyProvider;
import org.traccar.web.client.widget.LanguageComboBox;
import org.traccar.web.shared.model.ApplicationSettings;
import org.traccar.web.shared.model.*;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.Editor;
Expand All @@ -34,7 +35,6 @@
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.widget.core.client.Window;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import org.traccar.web.shared.model.PasswordHashMethod;

import java.util.Arrays;

Expand Down Expand Up @@ -92,6 +92,9 @@ public interface ApplicationSettingsHandler {
@UiField
TextField bingMapsKey;

@UiField(provided = true)
ComboBox<MatchServiceType> matchServiceType;

@UiField
TextField matchServiceURL;

Expand All @@ -107,6 +110,18 @@ public ApplicationSettingsDialog(ApplicationSettings applicationSettings, Applic
defaultHashImplementation.setForceSelection(true);
defaultHashImplementation.setTriggerAction(ComboBoxCell.TriggerAction.ALL);

ListStore<MatchServiceType> mstStore = new ListStore<>(new EnumKeyProvider<MatchServiceType>());
mstStore.addAll(Arrays.asList(MatchServiceType.values()));
matchServiceType = new ComboBox<>(mstStore, new ApplicationSettingsProperties.MatchServiceTypeLabelProvider());
matchServiceType.setForceSelection(true);
matchServiceType.setTriggerAction(ComboBoxCell.TriggerAction.ALL);
matchServiceType.addSelectionHandler(new SelectionHandler<MatchServiceType>() {
@Override
public void onSelection(SelectionEvent<MatchServiceType> event) {
matchServiceURL.setValue(event.getSelectedItem().getDefaultURL());
}
});

language = new LanguageComboBox();

uiBinder.createAndBindUi(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@
</form:widget>
</form:FieldLabel>
</container:child>
<container:child layoutData="{verticalLayoutData}">
<form:FieldLabel text="{i18n.matchServiceType} ({i18n.snapToRoads})" labelWidth="230">
<form:widget>
<form:ComboBox ui:field="matchServiceType" />
</form:widget>
</form:FieldLabel>
</container:child>
<container:child layoutData="{verticalLayoutData}">
<form:FieldLabel text="{i18n.matchServiceURL} ({i18n.snapToRoads})" labelWidth="230">
<form:widget>
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/traccar/web/server/model/DBMigrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void migrate(EntityManager em) throws Exception {
new SetGeoFenceAllDevicesFlag(),
new SetReportsFilterAndPreview(),
new SetDefaultExpiredFlagForEvents(),
new SetDefaultMatchServiceURL(),
new SetDefaultMatchServiceSettings(),
new RemoveMapQuest()
}) {
em.getTransaction().begin();
Expand Down Expand Up @@ -448,11 +448,17 @@ public void migrate(EntityManager em) throws Exception {
}
}

static class SetDefaultMatchServiceURL implements Migration {
static class SetDefaultMatchServiceSettings implements Migration {
@Override
public void migrate(EntityManager em) throws Exception {
em.createQuery("UPDATE " + ApplicationSettings.class.getName() + " S SET S.matchServiceURL = :url WHERE S.matchServiceURL IS NULL")
.setParameter("url", ApplicationSettings.DEFAULT_MATCH_SERVICE_URL)
// for existing installations, which are using v4 and has no 'matchServiceType' set yet
em.createQuery("UPDATE " + ApplicationSettings.class.getName() + " S SET S.matchServiceType = :msType WHERE S.matchServiceURL IS NOT NULL")
.setParameter("msType", MatchServiceType.OSRM_V4)
.executeUpdate();
// for new installations without match service type set
em.createQuery("UPDATE " + ApplicationSettings.class.getName() + " S SET S.matchServiceType = :msType, S.matchServiceURL = :url WHERE S.matchServiceType IS NULL")
.setParameter("msType", MatchServiceType.OSRM_V5)
.setParameter("url", MatchServiceType.OSRM_V5.getDefaultURL())
.executeUpdate();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class ApplicationSettings implements IsSerializable {
private static final long serialVersionUID = 1;
public static final short DEFAULT_UPDATE_INTERVAL = 15000;
public static final short DEFAULT_NOTIFICATION_EXPIRATION_PERIOD = 12 * 60;
public static final String DEFAULT_MATCH_SERVICE_URL = "https://router.project-osrm.org/match";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -28,7 +27,8 @@ public ApplicationSettings() {
eventRecordingEnabled = true;
language = "default";
notificationExpirationPeriod = DEFAULT_NOTIFICATION_EXPIRATION_PERIOD;
matchServiceURL = DEFAULT_MATCH_SERVICE_URL;
matchServiceType = MatchServiceType.OSRM_V4;
matchServiceURL = matchServiceType.getDefaultURL();
}

private boolean registrationEnabled;
Expand Down Expand Up @@ -129,6 +129,17 @@ public void setNotificationExpirationPeriod(int notificationExpirationPeriod) {
this.notificationExpirationPeriod = notificationExpirationPeriod;
}

@Enumerated(EnumType.STRING)
private MatchServiceType matchServiceType;

public MatchServiceType getMatchServiceType() {
return matchServiceType;
}

public void setMatchServiceType(MatchServiceType matchServiceType) {
this.matchServiceType = matchServiceType;
}

private String matchServiceURL;

public String getMatchServiceURL() {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/traccar/web/shared/model/MatchServiceType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016 Vitaly Litvak ([email protected])
*
* 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 org.traccar.web.shared.model;

public enum MatchServiceType {
OSRM_V4("OSRM v4", "https://router.project-osrm.org/match"),
OSRM_V5("OSRM v5", "https://router.project-osrm.org/match/v1/");

private final String name;
private final String defaultURL;

MatchServiceType(String name, String defaultURL) {
this.name = name;
this.defaultURL = defaultURL;
}

public String getName() {
return name;
}

public String getDefaultURL() {
return defaultURL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;

public enum PasswordHashMethod implements IsSerializable {
PLAIN("plain") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ eventRecordingEnabled = Event recording
defaultHashImplementation = Default password hash
bingMapsKey = Bing Maps key
notificationExpiryPeriod = Notification expiry period
matchServiceType = OSRM service type
matchServiceURL = OSRM service URL
# archive view
archive = Archive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ eventRecordingEnabled = Запись событий
defaultHashImplementation = Хэш-функция паролей
bingMapsKey = Ключ Bing Maps
notificationExpiryPeriod = Срок годности уведомлений
matchServiceType = Тип сервера OSRM
matchServiceURL = Адрес сервера OSRM
# archive view
archive = Архив
Expand Down

0 comments on commit 6e43877

Please sign in to comment.