Skip to content

Commit

Permalink
For #85 - moved pictures related logic to the new service - PicturesS…
Browse files Browse the repository at this point in the history
…ervice
  • Loading branch information
vitalidze committed May 25, 2015
1 parent 6a171a1 commit ecaf830
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/main/java/org/traccar/web/client/model/DataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,4 @@ public interface DataService extends RemoteService {
Map<User, Boolean> getGeoFenceShare(GeoFence geoFence);

void saveGeoFenceShare(GeoFence geoFence, Map<User, Boolean> share);

List<DeviceIcon> getMarkerPictures();
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,4 @@ public interface DataServiceAsync {
void getGeoFenceShare(GeoFence geoFence, AsyncCallback<Map<User, Boolean>> async);

void saveGeoFenceShare(GeoFence geoFence, Map<User, Boolean> share, AsyncCallback<Void> async);

void getMarkerPictures(AsyncCallback<List<DeviceIcon>> async);
}
27 changes: 27 additions & 0 deletions src/main/java/org/traccar/web/client/model/PicturesService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2015 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.client.model;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import org.traccar.web.shared.model.DeviceIcon;

import java.util.List;

@RemoteServiceRelativePath("picturesService")
public interface PicturesService extends RemoteService {
List<DeviceIcon> getMarkerPictures();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.traccar.web.client.model;

import com.google.gwt.user.client.rpc.AsyncCallback;
import org.traccar.web.shared.model.DeviceIcon;

import java.util.List;

public interface PicturesServiceAsync {
void getMarkerPictures(AsyncCallback<List<DeviceIcon>> async);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.traccar.web.client.i18n.Messages;
import org.traccar.web.client.model.BaseAsyncCallback;
import org.traccar.web.client.model.BaseStoreHandlers;
import org.traccar.web.client.model.PicturesService;
import org.traccar.web.client.model.PicturesServiceAsync;
import org.traccar.web.shared.model.DeviceIcon;
import org.traccar.web.shared.model.DeviceIconType;
import org.traccar.web.shared.model.Picture;
Expand Down Expand Up @@ -133,6 +135,8 @@ public interface DeviceMarkerHandler {
@UiField(provided = true)
final Messages i18n = GWT.create(Messages.class);

final PicturesServiceAsync picturesService = GWT.create(PicturesService.class);

final DeviceMarkerHandler handler;

static abstract class Marker {
Expand Down Expand Up @@ -256,7 +260,7 @@ final DeviceIcon toDeviceIcon() {
RpcProxy<Object, List<Marker>> hybridProxy = new RpcProxy<Object, List<Marker>>() {
@Override
public void load(Object loadConfig, AsyncCallback<List<Marker>> callback) {
Application.getDataService().getMarkerPictures(new MergingCallback(i18n, callback));
picturesService.getMarkerPictures(new MergingCallback(i18n, callback));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,4 @@ public void saveGeoFenceShare(GeoFence geoFence, Map<User, Boolean> share) {
entityManager.merge(user);
}
}

@Transactional
@RequireUser
@Override
public List<DeviceIcon> getMarkerPictures() {
return getSessionEntityManager().createQuery("SELECT i FROM DeviceIcon i ORDER BY i.id DESC", DeviceIcon.class)
.getResultList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected void configureServlets() {
serve("/traccar/uiStateService").with(UIStateServiceImpl.class);
serve("/traccar/eventService").with(EventServiceImpl.class);
serve("/traccar/notificationService").with(NotificationServiceImpl.class);
serve("/traccar/picturesService").with(PicturesServiceImpl.class);

serve("/traccar/rest/*").with(RESTApiServlet.class);
serve("/traccar/export/*").with(ExportServlet.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2015 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.server.model;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.persist.Transactional;
import org.traccar.web.client.model.PicturesService;
import org.traccar.web.shared.model.DeviceIcon;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.persistence.EntityManager;
import java.util.List;

@Singleton
public class PicturesServiceImpl extends RemoteServiceServlet implements PicturesService {
@Inject
private Provider<EntityManager> entityManager;

@Transactional
@RequireUser
@Override
public List<DeviceIcon> getMarkerPictures() {
return entityManager.get().createQuery("SELECT i FROM DeviceIcon i ORDER BY i.id DESC", DeviceIcon.class)
.getResultList();
}
}

0 comments on commit ecaf830

Please sign in to comment.