01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.pos.adaptor;
19:
20: import java.util.Map;
21: import java.sql.Timestamp;
22:
23: import org.ofbiz.service.GenericServiceCallback;
24: import org.ofbiz.base.util.Debug;
25: import org.ofbiz.base.util.UtilMisc;
26: import org.ofbiz.entity.GenericValue;
27: import org.ofbiz.entity.GenericEntityException;
28: import org.ofbiz.pos.screen.PosScreen;
29: import org.ofbiz.pos.event.SecurityEvents;
30:
31: public class SyncCallbackAdaptor implements GenericServiceCallback {
32:
33: public static final String module = SyncCallbackAdaptor.class
34: .getName();
35:
36: protected PosScreen screen = null;
37: protected Timestamp txStamp = null;
38: protected String entitySyncId = null;
39: protected boolean enabled = true;
40:
41: public SyncCallbackAdaptor(PosScreen pos, String entitySyncId,
42: Timestamp txStamp) {
43: this .screen = pos;
44: this .entitySyncId = entitySyncId;
45: this .txStamp = txStamp;
46: }
47:
48: public void setEnabled(boolean enabled) {
49: this .enabled = enabled;
50: }
51:
52: protected void internalReceiveEvent(Map context, Object obj) {
53: String ctxSyncId = (String) context.get("entitySyncId");
54: if (ctxSyncId != null && entitySyncId.equals(ctxSyncId)) {
55: GenericValue entitySync = null;
56: try {
57: entitySync = screen.getSession().getDelegator()
58: .findByPrimaryKey(
59: "EntitySync",
60: UtilMisc.toMap("entitySyncId",
61: entitySyncId));
62: } catch (GenericEntityException e) {
63: Debug.logError(e, module);
64: }
65: if (entitySync != null) {
66: Timestamp lastSync = entitySync
67: .getTimestamp("lastSuccessfulSynchTime");
68: if (lastSync.after(txStamp)) {
69: this .setEnabled(false);
70: screen.showDialog("dialog/error/terminalclosed");
71: screen.refresh();
72: SecurityEvents.logout(screen);
73: }
74: }
75: }
76: }
77:
78: public void receiveEvent(Map context) {
79: this .internalReceiveEvent(context, null);
80: }
81:
82: public void receiveEvent(Map context, Map result) {
83: this .internalReceiveEvent(context, result);
84: }
85:
86: public void receiveEvent(Map context, Throwable error) {
87: this .internalReceiveEvent(context, error);
88: }
89:
90: public boolean isEnabled() {
91: return this.enabled;
92: }
93: }
|