Initial commit
This commit is contained in:
22
kz_cafe_client/.classpath
Normal file
22
kz_cafe_client/.classpath
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/1_7_0_45">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="jst.web"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/kz_cafe_core">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
37
kz_cafe_client/.project
Normal file
37
kz_cafe_client/.project
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>kz_cafe_client</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
<project>kz_cafe_core</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
12
kz_cafe_client/.settings/.jsdtscope
Normal file
12
kz_cafe_client/.settings/.jsdtscope
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="WebContent"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
|
||||
<attributes>
|
||||
<attribute name="hide" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
||||
11
kz_cafe_client/.settings/org.eclipse.jdt.core.prefs
Normal file
11
kz_cafe_client/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
59
kz_cafe_client/.settings/org.eclipse.wst.common.component
Normal file
59
kz_cafe_client/.settings/org.eclipse.wst.common.component
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="kz_cafe_client">
|
||||
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
|
||||
<dependent-module archiveName="kz_cafe_core.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/kz_cafe_core/kz_cafe_core">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="mailapi.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/mailapi.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="jersey-json-1.5.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/jersey-json-1.5.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="smtp.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/smtp.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="jsr311-api-1.1.1.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/jsr311-api-1.1.1.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="morphia-1.00-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/morphia-1.00-SNAPSHOT.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="jersey-client-1.5.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/jersey-client-1.5.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="jersey-core-1.5.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/jersey-core-1.5.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="commons-logging.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/commons-logging.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="commons-collections-3.1.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/commons-collections-3.1.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="imap.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/imap.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="mongo-2.6.3.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/mongo-2.6.3.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="pop3.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/pop3.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="sqlitejdbc-v056.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/sqlitejdbc-v056.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="log4j.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/log4j.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="asm-3.1.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/asm-3.1.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="jersey-server-1.5.jar" deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/kz_cafe_core/lib/jersey-server-1.5.jar">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<property name="context-root" value="kz_cafe_client"/>
|
||||
<property name="java-output-path" value="/kz_cafe_client/build/classes"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<runtime name="Apache Tomcat v6.0"/>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<fixed facet="java"/>
|
||||
<fixed facet="jst.web"/>
|
||||
<installed facet="java" version="1.7"/>
|
||||
<installed facet="jst.web" version="2.5"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
</faceted-project>
|
||||
@@ -0,0 +1 @@
|
||||
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
|
||||
@@ -0,0 +1 @@
|
||||
Window
|
||||
3
kz_cafe_client/WebContent/META-INF/MANIFEST.MF
Normal file
3
kz_cafe_client/WebContent/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
BIN
kz_cafe_client/WebContent/WEB-INF/lib/asm-3.1.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/asm-3.1.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/commons-io-2.0.1.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/commons-io-2.0.1.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/commons-logging.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/commons-logging.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-client-1.5.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-client-1.5.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-core-1.5.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-core-1.5.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-json-1.5.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-json-1.5.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-server-1.5.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jersey-server-1.5.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jsr311-api-1.1.1.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/jsr311-api-1.1.1.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/log4j.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/log4j.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/mailapi.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/mailapi.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/mongo-2.6.3.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/mongo-2.6.3.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/morphia-1.00-SNAPSHOT.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/morphia-1.00-SNAPSHOT.jar
Normal file
Binary file not shown.
BIN
kz_cafe_client/WebContent/WEB-INF/lib/sqlitejdbc-v056.jar
Normal file
BIN
kz_cafe_client/WebContent/WEB-INF/lib/sqlitejdbc-v056.jar
Normal file
Binary file not shown.
32
kz_cafe_client/WebContent/WEB-INF/web.xml
Normal file
32
kz_cafe_client/WebContent/WEB-INF/web.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
|
||||
<display-name></display-name>
|
||||
<servlet>
|
||||
<servlet-name>ServletAdaptor</servlet-name>
|
||||
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.config.property.packages</param-name>
|
||||
<param-value>kz.cafe.client</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.config.property.MediaTypeMappings</param-name>
|
||||
<param-value>json : application/json</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
|
||||
<param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>ServletAdaptor</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<welcome-file-list>
|
||||
<welcome-file>index.html</welcome-file>
|
||||
<welcome-file>index.htm</welcome-file>
|
||||
<welcome-file>index.jsp</welcome-file>
|
||||
<welcome-file>default.html</welcome-file>
|
||||
<welcome-file>default.htm</welcome-file>
|
||||
<welcome-file>default.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
</web-app>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEAdmin.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEAdmin.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FECafe.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FECafe.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FECity.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FECity.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEImages.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEImages.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEMessage.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEMessage.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FENews.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FENews.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEPhone.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEPhone.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FESale.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FESale.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FESystem.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FESystem.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEUser$1.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEUser$1.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEUser.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/client/rest/FEUser.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/security/Adresses.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/security/Adresses.class
Normal file
Binary file not shown.
BIN
kz_cafe_client/build/classes/kz/cafe/security/Sessions.class
Normal file
BIN
kz_cafe_client/build/classes/kz/cafe/security/Sessions.class
Normal file
Binary file not shown.
Binary file not shown.
484
kz_cafe_client/src/kz/cafe/client/FEAbstractService.java
Normal file
484
kz_cafe_client/src/kz/cafe/client/FEAbstractService.java
Normal file
@@ -0,0 +1,484 @@
|
||||
package kz.cafe.client;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.zip.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.logs.*;
|
||||
import kz.cafe.db.logs.model.*;
|
||||
import kz.cafe.db.model.*;
|
||||
import kz.cafe.exceptions.*;
|
||||
import kz.cafe.security.*;
|
||||
import kz.cafe.statistics.*;
|
||||
import org.apache.commons.logging.*;
|
||||
import com.google.code.morphia.query.*;
|
||||
|
||||
|
||||
public abstract class FEAbstractService{
|
||||
private Log log = LogFactory.getLog(FEAbstractService.class);
|
||||
|
||||
private final String LOG;
|
||||
|
||||
protected ServiceRequestModel srm;
|
||||
|
||||
|
||||
protected long lStartTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
protected int UID;
|
||||
|
||||
|
||||
|
||||
|
||||
public FEAbstractService(ServiceRequestModel srm, String LOG){
|
||||
|
||||
long lThreadID = MongoService.getUniqueRequestID();
|
||||
|
||||
this.srm = srm;
|
||||
|
||||
this.LOG = LOG;
|
||||
|
||||
Thread.currentThread().setName("" + lThreadID);
|
||||
|
||||
log.info(LOG + "\n" + LogConstants.LOG_NEW_REQUEST + "Incoming Request from: " + srm.remoteAddress);
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_TOTAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected void responseTime(JRAbstractResponse response){
|
||||
responseTime(response, -1L, null, true);
|
||||
}
|
||||
// protected void responseTime(JRAbstractResponse response, UserSession3 session3){
|
||||
// responseTime(response, getUID(session3), getSID(session3), true);
|
||||
// }
|
||||
// protected void responseTime(JRAbstractResponse response, UserSession4 session4){
|
||||
// responseTime(response, getUID(session4), getSID(session4), true);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// protected void responseTime(JRAbstractResponse response,
|
||||
// UserSession3 session3,
|
||||
// boolean bCompress){
|
||||
// responseTime(response, session3.profile.UID, session3.SID, bCompress);
|
||||
// }
|
||||
// protected void responseTime(JRAbstractResponse response,
|
||||
// UserSession4 session4,
|
||||
// boolean bCompress){
|
||||
// responseTime(response, session4.profile.UID, session4.SID, bCompress);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// protected void responseTime(JRAbstractRequest jrAbstractRequest,
|
||||
// JRAbstractResponse response,
|
||||
// UserSession4 session4){
|
||||
//
|
||||
// responseTime(jrAbstractRequest.toString(), response.toString(), getUID(session4), getSID(session4), true);
|
||||
// }
|
||||
// protected void responseTime(String POST,
|
||||
// JRAbstractResponse response,
|
||||
// UserSession4 session4){
|
||||
// responseTime(POST, response.toString(), getUID(session4), getSID(session4), true);
|
||||
// }
|
||||
// protected void responseTime(JRAbstractRequest jrAbstractRequest,
|
||||
// String sResponse,
|
||||
// UserSession4 session4){
|
||||
// responseTime(jrAbstractRequest.toString(), sResponse, getUID(session4), getSID(session4), true);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected void responseTime(JRAbstractResponse response, Long UID, String SID, boolean bCompress){
|
||||
responseTime(null, response.toString(), UID, SID, bCompress);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected void responseTime(String sResponse, Long UID){
|
||||
responseTime(null, sResponse, UID, "SYSTEM OPERATION", true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// protected void responseTime(String sResponse, UserSession4 session4){
|
||||
// responseTime(null, sResponse, getUID(session4), getSID(session4), true);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// private long getUID(UserSession4 session4){
|
||||
// if(session4 == null || session4.profile == null){
|
||||
// return -1;
|
||||
// }
|
||||
// else{
|
||||
// return session4.profile.UID;
|
||||
// }
|
||||
// }
|
||||
// private long getUID(UserSession3 session3){
|
||||
// if(session3 == null || session3.profile == null){
|
||||
// return -1;
|
||||
// }
|
||||
// else{
|
||||
// return session3.profile.UID;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// private String getSID(UserSession4 session4){
|
||||
// if(session4 == null){
|
||||
// return null;
|
||||
// }
|
||||
// else{
|
||||
// return session4.SID;
|
||||
// }
|
||||
// }
|
||||
// private String getSID(UserSession3 session3){
|
||||
// if(session3 == null){
|
||||
// return null;
|
||||
// }
|
||||
// else{
|
||||
// return session3.SID;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
protected void responseTime(String sPOST, String sResponse, Long UID, String SID,
|
||||
boolean bCompress){
|
||||
MLogHeader mLogHeader = new MLogHeader();
|
||||
mLogHeader.IP = srm.remoteIP;
|
||||
mLogHeader.date = System.currentTimeMillis();
|
||||
mLogHeader.performance = mLogHeader.date - lStartTime;
|
||||
mLogHeader.name = this.getClass().getSimpleName();
|
||||
mLogHeader.request_url = srm.URL;
|
||||
mLogHeader.request_post = sPOST;
|
||||
mLogHeader.UID = UID;
|
||||
mLogHeader.SID = SID;
|
||||
mLogHeader = MongoLogService.addHeader(mLogHeader);
|
||||
|
||||
if(bCompress) {
|
||||
try{
|
||||
MLogBody mLogBody = new MLogBody();
|
||||
mLogBody.header = mLogHeader._id;
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
|
||||
ObjectOutputStream objectOut = new ObjectOutputStream(gzipOut);
|
||||
objectOut.writeObject(sResponse);
|
||||
objectOut.close();
|
||||
|
||||
mLogBody.response = baos.toByteArray();
|
||||
MongoLogService.addBody(mLogBody);
|
||||
}
|
||||
catch (Throwable e){
|
||||
throw new Error("Can not ZIP the '" + sResponse + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ClientCounters.addRequestTime(this.getClass(), mLogHeader.performance);
|
||||
|
||||
log.info(LOG + "Request time=" + mLogHeader.performance + "ms");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected static final String getCRC32(byte[] data) {
|
||||
Checksum checksum = new CRC32();
|
||||
checksum.update(data, 0, data.length);
|
||||
long lCRC32 = checksum.getValue();
|
||||
|
||||
return java.lang.Long.toHexString(lCRC32).toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected static final String getMD5(byte[] data) throws Exception{
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(data);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
bos.close();
|
||||
byte[] arrbyteData = bos.toByteArray();
|
||||
|
||||
md.update(arrbyteData);
|
||||
byte[] mdbytes = md.digest();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < mdbytes.length; i++){
|
||||
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// protected JMMIME mimeTypeDetector(String sFileName){
|
||||
// JMMIME jmMIME = new JMMIME();
|
||||
//
|
||||
// if(sFileName.endsWith(".jpg")){
|
||||
// jmMIME.code = 3;
|
||||
// jmMIME.name = "image/jpeg";
|
||||
// }
|
||||
// else if(sFileName.endsWith(".gif")){
|
||||
// jmMIME.code = 10;
|
||||
// jmMIME.name = "image/gif";
|
||||
// }
|
||||
// else if(sFileName.endsWith(".png")){
|
||||
// jmMIME.code = 115;
|
||||
// jmMIME.name = "image/png";
|
||||
// }
|
||||
//
|
||||
// return jmMIME;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected String uglyPath(List<PathSegment> uglyPath){
|
||||
StringBuilder sbUglyPath = new StringBuilder();
|
||||
|
||||
for(PathSegment pathSegment : uglyPath){
|
||||
if(sbUglyPath.length() > 0) {
|
||||
sbUglyPath.append("/");
|
||||
}
|
||||
sbUglyPath.append(pathSegment.getPath());
|
||||
}
|
||||
|
||||
if(sbUglyPath.charAt(0) == '/' && sbUglyPath.charAt(1) == '/'){
|
||||
sbUglyPath.replace(0, 2, "/");
|
||||
}
|
||||
|
||||
return sbUglyPath.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected List<String> uglyPath2Array(List<PathSegment> uglyPath){
|
||||
List<String> listResult = new ArrayList<String>();
|
||||
|
||||
for(PathSegment pathSegment : uglyPath){
|
||||
listResult.add(pathSegment.getPath());
|
||||
}
|
||||
|
||||
return listResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected List<Long> string2LongArray(String sLongArray){
|
||||
|
||||
List<Long> listResult = new ArrayList<Long>();
|
||||
|
||||
String[] arrTSes = sLongArray.split(",");
|
||||
for(String sTS : arrTSes){
|
||||
listResult.add(Long.parseLong(sTS));
|
||||
}
|
||||
|
||||
return listResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void checkSession(String SID) throws AbstractSecurityException{
|
||||
try{
|
||||
this.UID = Sessions.getUID(sid2Long(SID));
|
||||
}
|
||||
catch (Exception e){
|
||||
throw new SessionNotFoundException(SID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected InterfaceConstants.LANGS checkLanguage(String sLang) throws AbstractException{
|
||||
try{
|
||||
return InterfaceConstants.LANGS.valueOf(sLang);
|
||||
}
|
||||
catch (Throwable e){
|
||||
throw new LangNotSupportedException(sLang);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected String long2sid(long SID){
|
||||
return Long.toHexString(SID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected long sid2Long(String SID){
|
||||
return Long.parseLong(SID, 16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected InterfaceConstants.LANGS validateLang(String sLang) throws AbstractException{
|
||||
try{
|
||||
return InterfaceConstants.LANGS.valueOf(sLang);
|
||||
}
|
||||
catch (IllegalArgumentException e){
|
||||
StringBuffer sbTmp = new StringBuffer();
|
||||
|
||||
for(InterfaceConstants.LANGS tmp : InterfaceConstants.LANGS.values()){
|
||||
if(sbTmp.length() > 0){
|
||||
sbTmp.append(", ");
|
||||
}
|
||||
|
||||
sbTmp.append(tmp);
|
||||
}
|
||||
|
||||
throw new BadDataException("LANG", "sLang", sbTmp.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected void updateStatistic(String sField){
|
||||
String sIP = srm.remoteIP;
|
||||
Query<MStatisticIP> q =
|
||||
MongoService.ds.createQuery(MStatisticIP.class).filter(MStatisticIP.F_IP, sIP);
|
||||
if(q.countAll() == 0){
|
||||
MStatisticIP mStatisticIP = new MStatisticIP();
|
||||
mStatisticIP.ID = MongoService.getUniqueID(MStatisticIP.class);
|
||||
mStatisticIP.IP = sIP;
|
||||
try{
|
||||
MongoService.ds.save(mStatisticIP);
|
||||
}
|
||||
catch (Throwable e){
|
||||
}
|
||||
}
|
||||
UpdateOperations<MStatisticIP> uOps =
|
||||
MongoService.ds.createUpdateOperations(MStatisticIP.class).inc(sField);
|
||||
MongoService.ds.findAndModify(q, uOps);
|
||||
|
||||
|
||||
long lDate = (System.currentTimeMillis() / 1000 / 60 / 60 / 24) * 24 * 60 * 60 * 1000;
|
||||
Query<MStatisticDate> q2 =
|
||||
MongoService.ds.createQuery(MStatisticDate.class).filter(MStatisticDate.F_DATE, lDate);
|
||||
if(q2.countAll() == 0){
|
||||
try{
|
||||
MStatisticDate mStatisticDate = new MStatisticDate();
|
||||
mStatisticDate.ID = MongoService.getUniqueID(MStatisticDate.class);
|
||||
mStatisticDate.date = lDate;
|
||||
MongoService.ds.save(mStatisticDate);
|
||||
}
|
||||
catch (Throwable e){
|
||||
}
|
||||
}
|
||||
UpdateOperations<MStatisticDate> uOps2 =
|
||||
MongoService.ds.createUpdateOperations(MStatisticDate.class).inc(sField);
|
||||
MongoService.ds.findAndModify(q2, uOps2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ConcurrentHashMap<Integer, MUser> mapUsers = new ConcurrentHashMap<Integer, MUser>();
|
||||
ConcurrentHashMap<Integer, MCafe> mapCafes = new ConcurrentHashMap<Integer, MCafe>();
|
||||
ConcurrentHashMap<Integer, MCity> mapCities = new ConcurrentHashMap<Integer, MCity>();
|
||||
public MUser getUser(int ID){
|
||||
MUser mUser = mapUsers.get(ID);
|
||||
|
||||
if(mUser == null){
|
||||
mUser = MongoService.get(MUser.class, ID);
|
||||
mapUsers.put(ID, mUser);
|
||||
return mUser;
|
||||
}
|
||||
else{
|
||||
return mUser;
|
||||
}
|
||||
}
|
||||
public MCafe getCafe(int ID){
|
||||
MCafe mCafe = mapCafes.get(ID);
|
||||
|
||||
if(mCafe == null){
|
||||
mCafe = MongoService.get(MCafe.class, ID);
|
||||
mapCafes.put(ID, mCafe);
|
||||
return mCafe;
|
||||
}
|
||||
else{
|
||||
return mCafe;
|
||||
}
|
||||
}
|
||||
public MCity getCity(int ID){
|
||||
MCity mCity = mapCities.get(ID);
|
||||
|
||||
if(mCity == null){
|
||||
mCity = MongoService.get(MCity.class, ID);
|
||||
mapCities.put(ID, mCity);
|
||||
return mCity;
|
||||
}
|
||||
else{
|
||||
return mCity;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
kz_cafe_client/src/kz/cafe/client/JRAbstractRequest.java
Normal file
26
kz_cafe_client/src/kz/cafe/client/JRAbstractRequest.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package kz.cafe.client;
|
||||
|
||||
import java.io.*;
|
||||
import javax.xml.bind.*;
|
||||
|
||||
public abstract class JRAbstractRequest{
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
try{
|
||||
JAXBContext context = JAXBContext.newInstance(this.getClass());
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
|
||||
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
marshaller.marshal(this, sw);
|
||||
|
||||
return sw.toString();
|
||||
}
|
||||
catch (Throwable e){
|
||||
throw new Error("Can not marshall", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
136
kz_cafe_client/src/kz/cafe/client/JRAbstractResponse.java
Normal file
136
kz_cafe_client/src/kz/cafe/client/JRAbstractResponse.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package kz.cafe.client;
|
||||
|
||||
import java.io.*;
|
||||
import javax.xml.bind.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.exceptions.*;
|
||||
import org.apache.commons.logging.*;
|
||||
|
||||
public abstract class JRAbstractResponse{
|
||||
private static Log log = LogFactory.getLog(JRAbstractResponse.class);
|
||||
|
||||
private static final String LOG = "[JR ABSTRACT] ";
|
||||
|
||||
public String requestID;
|
||||
public Integer operationCode;
|
||||
public String message;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public JRAbstractResponse(){
|
||||
this.operationCode = OperationConstants.SUCCESS;
|
||||
this.requestID = Thread.currentThread().getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public JRAbstractResponse(Throwable e){
|
||||
|
||||
// if(e instanceof se.vocab.v4.exceptions.security.SessionInvalidException){
|
||||
// }
|
||||
// else {
|
||||
// log.error(LOG + e, e);
|
||||
// }
|
||||
|
||||
log.error(LOG + e, e);
|
||||
|
||||
|
||||
|
||||
this.requestID = Thread.currentThread().getName();
|
||||
//this.message = e.toString();
|
||||
this.operationCode = OperationConstants.UNKNOWN_ERROR;
|
||||
|
||||
|
||||
|
||||
// if(e instanceof UserIsAlreadyLoggedException){
|
||||
// this.operationCode = OperationConstants.USER_ALREADY_LOGGED;
|
||||
// }
|
||||
// else if(e instanceof UserExpiredException){
|
||||
// this.operationCode = OperationConstants.USER_EXPIRED;
|
||||
// }
|
||||
// else if(e instanceof UserNotRegisteredException){
|
||||
// this.operationCode = OperationConstants.USER_NOT_EXISTS;
|
||||
// }
|
||||
// else if(e instanceof VT3SecurityException){
|
||||
// this.operationCode = OperationConstants.SECURITY_NOT_ENOUGH_RIGHTS;
|
||||
// }
|
||||
|
||||
|
||||
if(e instanceof AbstractException){
|
||||
AbstractException e1 = (AbstractException) e;
|
||||
this.operationCode = e1.getErrorCode();
|
||||
this.message = e1.getsMsg();
|
||||
|
||||
// if(e1 instanceof ServerDataCorruptedException){
|
||||
// // ServerDataCorruptedException e2 = (ServerDataCorruptedException)
|
||||
// // e1;
|
||||
//
|
||||
// if(e1.getOriginalException() == null){
|
||||
// }
|
||||
// else{
|
||||
// // this.message = e2.getOriginalException().getMessage();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else{
|
||||
this.message = e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public String toString(){
|
||||
// StringBuilder builder = new StringBuilder();
|
||||
// builder.append("requestID=");
|
||||
// builder.append(requestID);
|
||||
// builder.append(", operationCode=");
|
||||
// builder.append(operationCode);
|
||||
// builder.append(", message=");
|
||||
// builder.append(message);
|
||||
// return builder.toString();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
try{
|
||||
JAXBContext context = JAXBContext.newInstance(this.getClass());
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
|
||||
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
marshaller.marshal(this, sw);
|
||||
|
||||
return sw.toString();
|
||||
}
|
||||
catch (Throwable e){
|
||||
throw new Error("Can not marshall", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
kz_cafe_client/src/kz/cafe/client/JREmptyResponse.java
Normal file
21
kz_cafe_client/src/kz/cafe/client/JREmptyResponse.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package kz.cafe.client;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
|
||||
@XmlRootElement(name="response")
|
||||
public class JREmptyResponse extends JRAbstractResponse{
|
||||
|
||||
public JREmptyResponse(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public JREmptyResponse(Throwable e){
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
||||
36
kz_cafe_client/src/kz/cafe/client/ServiceRequestModel.java
Normal file
36
kz_cafe_client/src/kz/cafe/client/ServiceRequestModel.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package kz.cafe.client;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
|
||||
|
||||
|
||||
public class ServiceRequestModel{
|
||||
|
||||
public final String remoteAddress;
|
||||
public final String remoteIP;
|
||||
public final String URL;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public ServiceRequestModel(String remoteAddress, String remoteIP, String URL){
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.remoteIP = remoteIP;
|
||||
this.URL = URL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final ServiceRequestModel buildUpponServlet(HttpServletRequest hsr){
|
||||
ServiceRequestModel srm =
|
||||
new ServiceRequestModel(hsr.getRemoteHost() + ":" + hsr.getRemotePort() + "\n"
|
||||
+ hsr.getRequestURL(),
|
||||
hsr.getRemoteAddr(),
|
||||
hsr.getRequestURL().toString());
|
||||
|
||||
return srm;
|
||||
}
|
||||
}
|
||||
166
kz_cafe_client/src/kz/cafe/client/rest/FEAdmin.java
Normal file
166
kz_cafe_client/src/kz/cafe/client/rest/FEAdmin.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.logs.*;
|
||||
import kz.cafe.db.logs.model.*;
|
||||
|
||||
@Path("/admin")
|
||||
public class FEAdmin extends FEAbstractService{
|
||||
//private static Log log = LogFactory.getLog(FEAdmin.class);
|
||||
|
||||
private static final String LOG = "[ADMIN] ";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FEAdmin(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/log/body/{UID}/{date}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public String getUserLog(@PathParam("UID") long UID,
|
||||
@PathParam("date") long date) throws Exception{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<response>");
|
||||
|
||||
for(MLogHeader mLogRecord3 : MongoLogService.getUserLogHeader(UID, date)){
|
||||
try{
|
||||
ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(MongoLogService.getUserRecord(mLogRecord3._id).response);
|
||||
GZIPInputStream gzipIn = new GZIPInputStream(bais);
|
||||
ObjectInputStream objectIn = new ObjectInputStream(gzipIn);
|
||||
sb.append("" + objectIn.readObject());
|
||||
objectIn.close();
|
||||
}
|
||||
catch(Throwable e){
|
||||
throw new Error("Can not UNZIP binary data", e);
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("</response>");
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/log/headers/{UID}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public String getUserLogHeaders(@PathParam("UID") long UID) throws Exception{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<log>");
|
||||
|
||||
for(MLogHeader mLogRecord3 : MongoLogService.getUserLogHeaders(UID)){
|
||||
sb.append("<request>");
|
||||
sb.append("<date>" + LogConstants.formatDate(mLogRecord3.date) + "</date>");
|
||||
sb.append("<date>" + mLogRecord3.date + "</date>");
|
||||
sb.append("<time>" + mLogRecord3.performance + " ms</time>");
|
||||
sb.append("<ip>" + mLogRecord3.IP + "</ip>");
|
||||
sb.append("<url>" + mLogRecord3.request_url + "</url>");
|
||||
|
||||
if(mLogRecord3.request_post == null){
|
||||
// Well, it was GET
|
||||
}
|
||||
else{
|
||||
sb.append("<post>" + mLogRecord3.request_post + "</post>");
|
||||
}
|
||||
|
||||
sb.append("</request>");
|
||||
}
|
||||
|
||||
sb.append("</log>");
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/log/headers")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public String getLogHeaders() throws Exception{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<log>");
|
||||
|
||||
for(MLogHeader mLogRecord3 : MongoLogService.getLogHeaders(1000)){
|
||||
sb.append("<request>");
|
||||
sb.append("<date>" + LogConstants.formatDate(mLogRecord3.date) + "</date>");
|
||||
sb.append("<date>" + mLogRecord3.date + "</date>");
|
||||
sb.append("<time>" + mLogRecord3.performance + " ms</time>");
|
||||
sb.append("<ip>" + mLogRecord3.IP + "</ip>");
|
||||
sb.append("<url>" + mLogRecord3.request_url + "</url>");
|
||||
|
||||
if(mLogRecord3.request_post == null){
|
||||
// Well, it was GET
|
||||
}
|
||||
else{
|
||||
sb.append("<post>" + mLogRecord3.request_post + "</post>");
|
||||
}
|
||||
|
||||
sb.append("</request>");
|
||||
}
|
||||
|
||||
sb.append("</log>");
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// try{
|
||||
// ByteArrayInputStream bais = new ByteArrayInputStream(mLogRecord3.response);
|
||||
// GZIPInputStream gzipIn = new GZIPInputStream(bais);
|
||||
// ObjectInputStream objectIn = new ObjectInputStream(gzipIn);
|
||||
// sb.append("" + objectIn.readObject());
|
||||
// objectIn.close();
|
||||
// }
|
||||
// catch (Throwable e){
|
||||
// throw new Error("Can not UNZIP binary data");
|
||||
// }
|
||||
|
||||
}
|
||||
843
kz_cafe_client/src/kz/cafe/client/rest/FECafe.java
Normal file
843
kz_cafe_client/src/kz/cafe/client/rest/FECafe.java
Normal file
@@ -0,0 +1,843 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import org.apache.commons.logging.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
import kz.cafe.db.service.*;
|
||||
import kz.cafe.exceptions.*;
|
||||
import kz.cafe.utils.*;
|
||||
|
||||
|
||||
|
||||
@Path("/cafe")
|
||||
public class FECafe extends FEAbstractService{
|
||||
private static Log log = LogFactory.getLog(FECafe.class);
|
||||
|
||||
private static final String LOG = "[JR CAFE] ";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// private UserSession4 session = null;
|
||||
|
||||
public FECafe(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@GET
|
||||
@Path("/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRCafeListResponse list(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
JRCafeListResponse response = new JRCafeListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MCafe mCafe : (List<MCafe>) MongoService.getListFrontEnd(MCafe.class, lTime)){
|
||||
|
||||
if(response.checkDeleted(mCafe)){
|
||||
JRCafeListResponse.JMItem item = response.add();
|
||||
|
||||
item.fillIn(lang, mCafe);
|
||||
try{
|
||||
item.type = mCafe.types.iterator().next();
|
||||
}
|
||||
catch (Exception e){
|
||||
item.type = 0;
|
||||
}
|
||||
item.rate = mCafe.rate;
|
||||
item.price = mCafe.price;
|
||||
|
||||
|
||||
//With no GMT
|
||||
item.timeClose = mCafe.timeCloseMo;
|
||||
item.timeOpen = mCafe.timeOpenMo;
|
||||
item.timeCloseWeekend = mCafe.timeCloseSa;
|
||||
item.timeOpenWeekend = mCafe.timeOpenSa;
|
||||
|
||||
|
||||
|
||||
item.phone = mCafe.phone;
|
||||
item.address = mCafe.address.get(lang);
|
||||
|
||||
if(mCafe.service == null || mCafe.service.size() == 0){
|
||||
item.service = "";
|
||||
}
|
||||
else{
|
||||
String sService = mCafe.service.toString();
|
||||
item.service = sService.substring(1, sService.length() - 1);
|
||||
}
|
||||
|
||||
item.coordinates = mCafe.coordinates;
|
||||
|
||||
item.hasDelivery = mCafe.hasDelivery;
|
||||
item.hasReservation = mCafe.hasReservation;
|
||||
|
||||
if(mCafe.types == null || mCafe.types.size() == 0){
|
||||
item.types = "";
|
||||
}
|
||||
else{
|
||||
String sTypes = mCafe.types.toString();
|
||||
item.types = sTypes.substring(1, sTypes.length() - 1);
|
||||
}
|
||||
|
||||
if(mCafe.cuisines == null || mCafe.cuisines.size() == 0){
|
||||
item.cuisines = "";
|
||||
}
|
||||
else{
|
||||
String sCuisines = mCafe.cuisines.toString();
|
||||
item.cuisines = sCuisines.substring(1, sCuisines.length() - 1);
|
||||
}
|
||||
|
||||
if(mCafe.faceControl == null || mCafe.faceControl.size() == 0){
|
||||
item.requirements = "";
|
||||
}
|
||||
else{
|
||||
String sFaceControl = mCafe.faceControl.toString();
|
||||
item.requirements = sFaceControl.substring(1, sFaceControl.length() - 1);
|
||||
}
|
||||
|
||||
item.tables_total = mCafe.tableTotal;
|
||||
item.tables_free = mCafe.tableFree;
|
||||
|
||||
item.bill_average_min = mCafe.bill_average_min;
|
||||
item.bill_average_max = mCafe.bill_average_max;
|
||||
|
||||
item.city = mCafe.city;
|
||||
|
||||
|
||||
//With no GMT
|
||||
item.timeCloseMo = mCafe.timeCloseMo;
|
||||
item.timeOpenMo = mCafe.timeOpenMo;
|
||||
item.timeCloseTu = mCafe.timeCloseTu;
|
||||
item.timeOpenTu = mCafe.timeOpenTu;
|
||||
item.timeCloseWe = mCafe.timeCloseWe;
|
||||
item.timeOpenWe = mCafe.timeOpenWe;
|
||||
item.timeCloseTh = mCafe.timeCloseTh;
|
||||
item.timeOpenTh = mCafe.timeOpenTh;
|
||||
item.timeCloseFr = mCafe.timeCloseFr;
|
||||
item.timeOpenFr = mCafe.timeOpenFr;
|
||||
item.timeCloseSa = mCafe.timeCloseSa;
|
||||
item.timeOpenSa = mCafe.timeOpenSa;
|
||||
item.timeCloseSu = mCafe.timeCloseSu;
|
||||
item.timeOpenSu = mCafe.timeOpenSu;
|
||||
|
||||
|
||||
|
||||
item.timeOrdersFrom = mCafe.timeOrdersFrom;
|
||||
item.timeOrdersTo = mCafe.timeOrdersTo;
|
||||
item.timeReservationFrom = mCafe.timeReservationFrom;
|
||||
item.timeReservationTo = mCafe.timeReservationTo;
|
||||
|
||||
|
||||
//Let's add GMT
|
||||
MCity mCity = getCity(mCafe.city);
|
||||
if(mCity == null){
|
||||
}
|
||||
else{
|
||||
item.timeClose -= mCity.GMT * 60;
|
||||
item.timeOpen -= mCity.GMT * 60;
|
||||
item.timeCloseWeekend -= mCity.GMT * 60;
|
||||
item.timeOpenWeekend -= mCity.GMT * 60;
|
||||
|
||||
item.timeCloseMo -= mCity.GMT * 60;
|
||||
item.timeOpenMo -= mCity.GMT * 60;
|
||||
item.timeCloseTu -= mCity.GMT * 60;
|
||||
item.timeOpenTu -= mCity.GMT * 60;
|
||||
item.timeCloseWe -= mCity.GMT * 60;
|
||||
item.timeOpenWe -= mCity.GMT * 60;
|
||||
item.timeCloseTh -= mCity.GMT * 60;
|
||||
item.timeOpenTh -= mCity.GMT * 60;
|
||||
item.timeCloseFr -= mCity.GMT * 60;
|
||||
item.timeOpenFr -= mCity.GMT * 60;
|
||||
item.timeCloseSa -= mCity.GMT * 60;
|
||||
item.timeOpenSa -= mCity.GMT * 60;
|
||||
item.timeCloseSu -= mCity.GMT * 60;
|
||||
item.timeOpenSu -= mCity.GMT * 60;
|
||||
|
||||
|
||||
//They are nullable
|
||||
if(item.timeOrdersFrom == null){
|
||||
}
|
||||
else{
|
||||
item.timeOrdersFrom -= mCity.GMT * 60;
|
||||
}
|
||||
if(item.timeOrdersTo == null){
|
||||
}
|
||||
else{
|
||||
item.timeOrdersTo -= mCity.GMT * 60;
|
||||
}
|
||||
if(item.timeReservationFrom == null){
|
||||
}
|
||||
else{
|
||||
item.timeReservationFrom -= mCity.GMT * 60;
|
||||
}
|
||||
if(item.timeReservationTo == null){
|
||||
}
|
||||
else{
|
||||
item.timeReservationTo -= mCity.GMT * 60;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JRCafeListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_MENU);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Images
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/image/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public JRCafeImageListResponse getFeedbacks(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
JRCafeImageListResponse response = new JRCafeImageListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MCafeImage mCafeImage : (List<MCafeImage>) MongoService.getListFrontEnd(
|
||||
MCafeImage.class, lTime)){
|
||||
if(response.checkDeleted(mCafeImage)){
|
||||
JRCafeImageListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mCafeImage);
|
||||
|
||||
item.CID = mCafeImage.CID;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JRCafeImageListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_FEEDBACKS);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@GET
|
||||
@Path("/menu/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRCourseListResponse listMenu(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
JRCourseListResponse response = new JRCourseListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MCourse mCourse : (List<MCourse>) MongoService.getListFrontEnd(MCourse.class, lTime)){
|
||||
|
||||
if(response.checkDeleted(mCourse)){
|
||||
JRCourseListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mCourse);
|
||||
item.category = mCourse.category;
|
||||
item.CID = mCourse.CID;
|
||||
item.price = mCourse.price;
|
||||
|
||||
String sIngredients = mCourse.ingredient.toString();
|
||||
item.ingredients = sIngredients.substring(1, sIngredients.length() - 1);
|
||||
|
||||
item.weight = mCourse.weight2.get(lang);
|
||||
item.delivery = mCourse.delivery;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JRCourseListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_MENU);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/reserve/list/{SID}/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRReserveListResponse listReservation(@PathParam("SID") String SID,
|
||||
@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
JRReserveListResponse response = new JRReserveListResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MReservation mReservation : MongoService.getReserves(super.UID, lTime)){
|
||||
if(response.checkDeleted(mReservation)){
|
||||
JRReserveListResponse.JMItem item = response.add();
|
||||
item.fillIn(mReservation);
|
||||
item.date = mReservation.date;
|
||||
item.CID = mReservation.CID;
|
||||
item.sits = mReservation.sits;
|
||||
item.comment = mReservation.comment.get(lang);
|
||||
item.confirmed = mReservation.confirmed;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JRReserveListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_MENU);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// add new reserver
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/reserve/new/{SID}/{date}/{CID}/{sits}/{lang}/{comment}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse newReservation(@PathParam("SID") String SID,
|
||||
@PathParam("date") long date,
|
||||
@PathParam("CID") int CID,
|
||||
@PathParam("sits") int iSits,
|
||||
@PathParam("lang") String sLang,
|
||||
@PathParam("comment") String sComment){
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MCafe mCafe = MongoService.getExceptionable(MCafe.class, CID);
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
MReservation mReservation = new MReservation();
|
||||
mReservation.ID = MongoService.getUniqueID(MReservation.class);
|
||||
mReservation.UID = super.UID;
|
||||
mReservation.ownerID = mCafe.ownerID;
|
||||
mReservation.CID = CID;
|
||||
mReservation.date = date;
|
||||
mReservation.sits = iSits;
|
||||
mReservation.comment.put(lang, sComment);
|
||||
|
||||
MongoService.save(mReservation);
|
||||
|
||||
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("cafe_name", mCafe.name);
|
||||
|
||||
MUser mUser = MongoService.get(MUser.class, UID);
|
||||
map.put("user_login", mUser.login);
|
||||
map.put("user_name", mUser.name);
|
||||
map.put("user_phone", mUser.phone);
|
||||
|
||||
map.put("sits", iSits);
|
||||
map.put("date", new SimpleDateFormat("HH:mm dd-MM-yyyy").format(date));
|
||||
map.put("comment", sComment);
|
||||
|
||||
|
||||
String sNewReservation = VelocityProc.run("new_reserve.vm", map);
|
||||
|
||||
//To Admin
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
ServerConstants.getEmailAddressSystemAdmin(),
|
||||
"Новый резерв в " + mCafe.name,
|
||||
sNewReservation);
|
||||
|
||||
//To cafe owner
|
||||
MUser mUserCafeOwner = MongoService.get(MUser.class, mCafe.ownerID);
|
||||
|
||||
log.info(LOG + "Email Notification for Admin=" + mUserCafeOwner.ID + " is " + (mUserCafeOwner.hasEmailNotifications ? "ON" : "OFF"));
|
||||
|
||||
if(mUserCafeOwner.hasEmailNotifications){
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
mUserCafeOwner.login,
|
||||
"Новый резерв в " + mCafe.name,
|
||||
sNewReservation);
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_FEEDBACK_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// add new order
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/order/new/{SID}/{CID}/{date}/{AID}/{lang}/{comment}/{paths:.+}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRNewOrderResponse newOrder(@PathParam("SID") String SID,
|
||||
@PathParam("CID") int CID,
|
||||
@PathParam("date") long date,
|
||||
@PathParam("AID") int AID,
|
||||
@PathParam("lang") String sLang,
|
||||
@PathParam("comment") String sComment,
|
||||
@PathParam("paths") List<PathSegment> uglyPath){
|
||||
JRNewOrderResponse response = new JRNewOrderResponse();
|
||||
|
||||
List<String> listOrderItems = uglyPath2Array(uglyPath);
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MCafe mCafe = MongoService.getExceptionable(MCafe.class, CID);
|
||||
|
||||
if(AID > 0){
|
||||
MongoService.getExceptionable(MSale.class, AID);
|
||||
}
|
||||
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
MOrder mOrder = new MOrder();
|
||||
mOrder.ID = MongoService.getUniqueID(MOrder.class);
|
||||
response.OID = mOrder.ID;
|
||||
|
||||
mOrder.CID = CID;
|
||||
|
||||
if(AID > 0){
|
||||
mOrder.AID = AID;
|
||||
}
|
||||
|
||||
mOrder.UID = super.UID;
|
||||
mOrder.comment.put(lang, sComment);
|
||||
mOrder.ownerID = mCafe.ownerID;
|
||||
|
||||
int iPrice = 0;
|
||||
List<VOrderItem> listVelocityItems = new ArrayList<VOrderItem>();
|
||||
|
||||
while (listOrderItems.size() > 0){
|
||||
int MID = Integer.parseInt(listOrderItems.remove(0));
|
||||
int iQuantity = Integer.parseInt(listOrderItems.remove(0));
|
||||
|
||||
MCourse mCourse = (MCourse) MongoService.getExceptionable(MCourse.class, MID);
|
||||
|
||||
MOrderItem mOrderItem = new MOrderItem();
|
||||
mOrderItem.ID = MongoService.getUniqueID(MOrderItem.class);
|
||||
mOrderItem.OID = mOrder.ID;
|
||||
mOrderItem.MID = MID;
|
||||
mOrderItem.quantity = iQuantity;
|
||||
mOrderItem.price = mCourse.price * iQuantity;
|
||||
MongoService.save(mOrderItem);
|
||||
|
||||
|
||||
iPrice += mOrderItem.price;
|
||||
|
||||
VOrderItem vOrderItem = new VOrderItem(mCourse.name,
|
||||
iQuantity,
|
||||
"" + new Float(mCourse.price) / 100);
|
||||
listVelocityItems.add(vOrderItem);
|
||||
}
|
||||
|
||||
mOrder.price = iPrice;
|
||||
MongoService.save(mOrder);
|
||||
|
||||
MongoOrderService.racalculteCounters(mOrder);
|
||||
|
||||
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("cafe_name", mCafe.name);
|
||||
|
||||
MUser mUser = MongoService.get(MUser.class, UID);
|
||||
map.put("user_login", mUser.login);
|
||||
map.put("user_name", mUser.name);
|
||||
map.put("user_phone", mUser.phone);
|
||||
|
||||
map.put("comment", sComment);
|
||||
|
||||
map.put("items", listVelocityItems);
|
||||
|
||||
map.put("price", "" + new Float(iPrice) / 100);
|
||||
|
||||
|
||||
String sNewOrder = VelocityProc.run("new_order.vm", map);
|
||||
|
||||
//To Admin
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
ServerConstants.getEmailAddressSystemAdmin(),
|
||||
"Новый заказ в " + mCafe.name,
|
||||
sNewOrder);
|
||||
|
||||
//To cafe owner
|
||||
MUser mUserCafeOwner = MongoService.get(MUser.class, mCafe.ownerID);
|
||||
|
||||
log.info(LOG + "Email Notification for Admin=" + mUserCafeOwner.ID + " is " + (mUserCafeOwner.hasEmailNotifications ? "ON" : "OFF"));
|
||||
|
||||
if(mUserCafeOwner.hasEmailNotifications){
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
mUserCafeOwner.login,
|
||||
"Новый заказ в " + mCafe.name,
|
||||
sNewOrder);
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JRNewOrderResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_ORDER_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static class VOrderItem{
|
||||
private final Map<InterfaceConstants.LANGS, String> name;
|
||||
private final int quantity;
|
||||
private final String price;
|
||||
|
||||
public VOrderItem(Map<InterfaceConstants.LANGS, String> name, int quantity, String price){
|
||||
this.name = name;
|
||||
this.quantity = quantity;
|
||||
this.price = price;
|
||||
}
|
||||
public Map<InterfaceConstants.LANGS, String> getName(){
|
||||
return name;
|
||||
}
|
||||
public int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
public String getPrice(){
|
||||
return price;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// update order
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/order/update/{SID}/{OID}/{CID}/{date}/{AID}/{lang}/{comment}/{paths:.+}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse updateOrder(@PathParam("SID") String SID,
|
||||
@PathParam("OID") int OID,
|
||||
@PathParam("CID") int CID,
|
||||
@PathParam("date") long date,
|
||||
@PathParam("AID") int AID,
|
||||
@PathParam("lang") String sLang,
|
||||
@PathParam("comment") String sComment,
|
||||
@PathParam("paths") List<PathSegment> uglyPath){
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
List<String> listOrders = uglyPath2Array(uglyPath);
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MCafe mCafe = MongoService.getExceptionable(MCafe.class, CID);
|
||||
MongoService.getExceptionable(MSale.class, AID);
|
||||
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
MOrder mOrder = MongoService.get(MOrder.class, OID);
|
||||
mOrder.CID = CID;
|
||||
|
||||
if(AID > 0){
|
||||
mOrder.AID = AID;
|
||||
}
|
||||
|
||||
mOrder.UID = super.UID;
|
||||
mOrder.comment.put(lang, sComment);
|
||||
mOrder.ownerID = mCafe.ownerID;
|
||||
|
||||
List<MOrderItem> listOrderItems = MongoService.ds.find(MOrderItem.class)
|
||||
.filter(MOrderItem.F_OID, OID).asList();
|
||||
|
||||
for(MOrderItem mOrderItem : listOrderItems){
|
||||
mOrderItem.deleted = true;
|
||||
}
|
||||
|
||||
while (listOrders.size() > 0){
|
||||
int MID = Integer.parseInt(listOrders.remove(0));
|
||||
int iQuantity = Integer.parseInt(listOrders.remove(1));
|
||||
|
||||
MOrderItem mOrderItem;
|
||||
if(listOrderItems.size() > 0){
|
||||
mOrderItem = listOrderItems.remove(0);
|
||||
}
|
||||
else{
|
||||
mOrderItem = new MOrderItem();
|
||||
mOrderItem.ID = MongoService.getUniqueID(MOrderItem.class);
|
||||
}
|
||||
|
||||
mOrderItem.OID = mOrder.ID;
|
||||
mOrderItem.MID = MID;
|
||||
mOrderItem.quantity = iQuantity;
|
||||
MongoService.save(mOrderItem);
|
||||
}
|
||||
|
||||
for(MOrderItem mOrderItem : listOrderItems){
|
||||
MongoService.save(mOrderItem);
|
||||
}
|
||||
|
||||
MongoService.save(mOrder);
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
// updateStatistic(MAbstractStatistics.F_ORDER_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// update order
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/order/list/{SID}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JROrderListResponse listOrders(@PathParam("SID") String SID){
|
||||
JROrderListResponse response = new JROrderListResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
List<MOrder> listOrders = MongoService.ds.find(MOrder.class)
|
||||
.filter(MOrder.F_UID, super.UID).asList();
|
||||
for(MOrder mOrder : listOrders){
|
||||
JROrderListResponse.JMOrder jmOrder = response.add();
|
||||
jmOrder.ID = mOrder.ID;
|
||||
jmOrder.CID = mOrder.CID;
|
||||
jmOrder.AID = mOrder.AID;
|
||||
|
||||
List<MOrderItem> listOrderItems = MongoService.ds.find(MOrderItem.class)
|
||||
.filter(MOrderItem.F_OID, mOrder.ID).asList();
|
||||
|
||||
for(MOrderItem mOrderItem : listOrderItems){
|
||||
JROrderListResponse.JMOrder.JMMeal jmMeal = jmOrder.add();
|
||||
jmMeal.IID = mOrderItem.MID;
|
||||
jmMeal.quantity = mOrderItem.quantity;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JROrderListResponse(e);
|
||||
}
|
||||
|
||||
// updateStatistic(MAbstractStatistics.F_ORDER_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// add new order
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/order/delivery/set/{SID}/{OID}/{CITY}/{STREET}/{BUILDING}/{APARTMENT}/{PHONE}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse setDeliveryAddress(@PathParam("SID") String SID,
|
||||
@PathParam("OID") int OID,
|
||||
@PathParam("CITY") int CityID,
|
||||
@PathParam("STREET") String sStreet,
|
||||
@PathParam("BUILDING") String sBuilding,
|
||||
@PathParam("APARTMENT") String sApartment,
|
||||
@PathParam("PHONE") String sPhone){
|
||||
|
||||
|
||||
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MOrder mOrder = MongoService.getExceptionable(MOrder.class, OID);
|
||||
if(mOrder.UID == UID){
|
||||
mOrder.deliveryCity = MongoService.getExceptionable(MCity.class, CityID).ID;;
|
||||
mOrder.deliveryStreet = sStreet;
|
||||
mOrder.deliveryBuilding = sBuilding;
|
||||
mOrder.deliveryApartment = sApartment;
|
||||
mOrder.deliveryPhone = sPhone;
|
||||
MongoService.save(mOrder);
|
||||
}
|
||||
else{
|
||||
throw new AccessDeniedException(MOrder.class, mOrder.ID);
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
// updateStatistic(MAbstractStatistics.F_ORDER_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Descriptors
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
@GET
|
||||
@Path("/ingredients/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRDescriptorListResponse ingredients(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
return getDescriptors(MIngredient.class, sLang, lTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/menu/category/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRDescriptorListResponse courseCategories(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
return getDescriptors(MCourseCategory.class, sLang, lTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/type/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRDescriptorListResponse cafeTypes(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
return getDescriptors(MCafeType.class, sLang, lTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/service/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRDescriptorListResponse serviceTypes(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
return getDescriptors(MServiceType.class, sLang, lTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/cuisine/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRDescriptorListResponse cuisines(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
return getDescriptors(MCuisine.class, sLang, lTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/req/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRDescriptorListResponse faceControl(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
|
||||
return getDescriptors(MFaceControl.class, sLang, lTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private JRDescriptorListResponse getDescriptors(Class clas, String sLang, long lTime){
|
||||
JRDescriptorListResponse response = new JRDescriptorListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MAbstractDescriptor mAbstractDescriptor :
|
||||
(List<MAbstractDescriptor>) MongoService.getListFrontEnd(clas, lTime)){
|
||||
|
||||
if(response.checkDeleted(mAbstractDescriptor)){
|
||||
JRDescriptorListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mAbstractDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JRDescriptorListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_MENU);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
63
kz_cafe_client/src/kz/cafe/client/rest/FECity.java
Normal file
63
kz_cafe_client/src/kz/cafe/client/rest/FECity.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
|
||||
@Path("/city")
|
||||
public class FECity extends FEAbstractService{
|
||||
// private static Log log = LogFactory.getLog(FESale.class);
|
||||
|
||||
private static final String LOG = "[JR SALE] ";
|
||||
|
||||
|
||||
|
||||
public FECity(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//Cities
|
||||
//---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public JRCityListResponse getCities(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
JRCityListResponse response = new JRCityListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MCity mCity : (List<MCity>) MongoService.getListFrontEnd(MCity.class, lTime)){
|
||||
if(response.checkDeleted(mCity)){
|
||||
JRCityListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mCity);
|
||||
|
||||
item.GMT = mCity.GMT;
|
||||
item.hasCafe = mCity.hasCafe;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRCityListResponse(e);
|
||||
}
|
||||
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
222
kz_cafe_client/src/kz/cafe/client/rest/FEFeedback.java
Normal file
222
kz_cafe_client/src/kz/cafe/client/rest/FEFeedback.java
Normal file
@@ -0,0 +1,222 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
import kz.cafe.db.service.*;
|
||||
import kz.cafe.utils.*;
|
||||
|
||||
|
||||
@Path("/feedback")
|
||||
public class FEFeedback extends FEAbstractService{
|
||||
//private static Log log = LogFactory.getLog(FEFeedback.class);
|
||||
|
||||
private static final String LOG = "[JR USER] ";
|
||||
|
||||
// private UserSession4 session = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FEFeedback(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//list
|
||||
//---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public JRFeedbackListResponse getFeedbacks(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
JRFeedbackListResponse response = new JRFeedbackListResponse();
|
||||
|
||||
InterfaceConstants.LANGS lang = InterfaceConstants.LANGS.valueOf(sLang);
|
||||
|
||||
try{
|
||||
for(MFeedback mFeedback : (List<MFeedback>) MongoService.getListFrontEnd(MFeedback.class, lTime)){
|
||||
|
||||
if(response.checkDeleted(mFeedback)){
|
||||
JRFeedbackListResponse.JMItem item = response.add();
|
||||
item.fillIn(mFeedback);
|
||||
|
||||
MUser mUser = getUser(mFeedback.UID);
|
||||
|
||||
item.CID = mFeedback.CID;
|
||||
item.avatar = item.checkIsImageEmpty(mUser.image);
|
||||
item.login = mUser.login;
|
||||
item.name = mUser.name;
|
||||
item.rate = mFeedback.rate;
|
||||
item.text = mFeedback.text.get(lang);
|
||||
item.title = mFeedback.title.get(lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRFeedbackListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_FEEDBACKS);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//add new
|
||||
//---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/new/{SID}/{CID}/{rate}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse newFeedbacks(@PathParam("SID") String SID,
|
||||
@PathParam("CID") int CID,
|
||||
@PathParam("rate") int iRate){
|
||||
|
||||
return newFeedbacks(SID, CID, iRate, null, null);
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/new/{SID}/{CID}/{rate}/{lang}/{text}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse newFeedbacks(@PathParam("SID") String SID,
|
||||
@PathParam("CID") int CID,
|
||||
@PathParam("rate") int iRate,
|
||||
@PathParam("lang") String sLang,
|
||||
@PathParam("text") String sText){
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MCafe mCafe = MongoService.getExceptionable(MCafe.class, CID);
|
||||
|
||||
MFeedback mFeedback = new MFeedback();
|
||||
mFeedback.ID = MongoService.getUniqueID(MFeedback.class);
|
||||
mFeedback.CID = mCafe.ID;
|
||||
mFeedback.UID = super.UID;
|
||||
mFeedback.ownerID = mCafe.ownerID;
|
||||
|
||||
if(sLang == null){
|
||||
}
|
||||
else{
|
||||
InterfaceConstants.LANGS lang = checkLanguage(sLang);
|
||||
mFeedback.text.put(lang, sText);
|
||||
}
|
||||
|
||||
mFeedback.rate = iRate;
|
||||
MongoService.save(mFeedback);
|
||||
|
||||
|
||||
MongoFeedbackService.racalculte(CID);
|
||||
|
||||
MUser mUser = MongoService.get(MUser.class, UID);
|
||||
sendEmail(mUser, mCafe, "", iRate, sText);
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_FEEDBACK_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/new/{SID}/{CID}/{rate}/{lang}/{text}/{title}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse newFeedbacks(@PathParam("SID") String SID,
|
||||
@PathParam("CID") int CID,
|
||||
@PathParam("rate") int iRate,
|
||||
@PathParam("lang") String sLang,
|
||||
@PathParam("text") String sText,
|
||||
@PathParam("title") String sTitle){
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MCafe mCafe = MongoService.getExceptionable(MCafe.class, CID);
|
||||
|
||||
MFeedback mFeedback = new MFeedback();
|
||||
mFeedback.ID = MongoService.getUniqueID(MFeedback.class);
|
||||
mFeedback.CID = mCafe.ID;
|
||||
mFeedback.UID = super.UID;
|
||||
mFeedback.ownerID = mCafe.ownerID;
|
||||
|
||||
if(sLang == null){
|
||||
}
|
||||
else{
|
||||
InterfaceConstants.LANGS lang = checkLanguage(sLang);
|
||||
mFeedback.text.put(lang, sText);
|
||||
|
||||
mFeedback.title.put(lang, sTitle);
|
||||
}
|
||||
|
||||
mFeedback.rate = iRate;
|
||||
MongoService.save(mFeedback);
|
||||
|
||||
|
||||
MongoFeedbackService.racalculte(CID);
|
||||
|
||||
MUser mUser = MongoService.get(MUser.class, UID);
|
||||
sendEmail(mUser, mCafe, sTitle, iRate, sText);
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_FEEDBACK_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void sendEmail(MUser mUser, MCafe mCafe, String sTitle, int iRate, String sText) throws Exception{
|
||||
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("cafe_name", mCafe.name);
|
||||
map.put("user_login", mUser.login);
|
||||
map.put("user_name", mUser.name);
|
||||
map.put("user_phone", mUser.phone);
|
||||
map.put("title", sTitle);
|
||||
map.put("rate", iRate);
|
||||
map.put("text", sText);
|
||||
|
||||
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
ServerConstants.getEmailAddressSystemAdmin(),
|
||||
"Новый отзыв",
|
||||
VelocityProc.run("new_feedback.vm", map));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
94
kz_cafe_client/src/kz/cafe/client/rest/FEImages.java
Normal file
94
kz_cafe_client/src/kz/cafe/client/rest/FEImages.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
import org.apache.commons.fileupload.*;
|
||||
import org.apache.commons.fileupload.disk.*;
|
||||
import org.apache.commons.fileupload.servlet.*;
|
||||
|
||||
|
||||
@Path("/images")
|
||||
public class FEImages extends FEAbstractService{
|
||||
|
||||
// private static Log log = LogFactory.getLog(FEImages.class);
|
||||
|
||||
private static final String LOG = "[JR IMAGE] ";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FEImages(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/new/{SID}")
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRImageResponse post(@PathParam("SID") String SID, @Context HttpServletRequest request){
|
||||
|
||||
JRImageResponse response = new JRImageResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
|
||||
if(ServletFileUpload.isMultipartContent(request)){
|
||||
FileItemFactory factory = new DiskFileItemFactory();
|
||||
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FileItem> items = upload.parseRequest(request);
|
||||
|
||||
if(items.size() == 0) {
|
||||
throw new Exception("Нет файла в запросе");
|
||||
}
|
||||
else{
|
||||
FileItem item = items.get(0);
|
||||
|
||||
String sFileExtension;
|
||||
|
||||
try{
|
||||
sFileExtension = item.getName().split("\\.")[1].trim();
|
||||
}
|
||||
catch (Exception e1){
|
||||
throw new Error("Имя файла должно содержать расширение");
|
||||
}
|
||||
|
||||
|
||||
String sFileName = MongoService.getUniqueID(MImage.class)
|
||||
+ "."
|
||||
+ sFileExtension;
|
||||
|
||||
FileOutputStream fout =
|
||||
new FileOutputStream(new File(ServerConstants.getImageFolder() + sFileName));
|
||||
|
||||
fout.write(item.get());
|
||||
|
||||
response.image = sFileName;
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Exception("Not a multipart form.");
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
return new JRImageResponse(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
129
kz_cafe_client/src/kz/cafe/client/rest/FEMessage.java
Normal file
129
kz_cafe_client/src/kz/cafe/client/rest/FEMessage.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
import kz.cafe.db.service.*;
|
||||
import kz.cafe.utils.*;
|
||||
|
||||
|
||||
@Path("/message")
|
||||
public class FEMessage extends FEAbstractService{
|
||||
//private static Log log = LogFactory.getLog(FEFeedback.class);
|
||||
|
||||
private static final String LOG = "[JR USER] ";
|
||||
|
||||
// private UserSession4 session = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FEMessage(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//add new
|
||||
//---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/system/new/{SID}/{lang}/{header}/{text}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse newSystemMessage(@PathParam("SID") String SID,
|
||||
@PathParam("lang") String sLang,
|
||||
@PathParam("header") String sHeader,
|
||||
@PathParam("text") String sText){
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
//MUser mUser = MongoUserService.getUserProfile(UID);
|
||||
|
||||
|
||||
MMessageSystem mMessageSystem = new MMessageSystem();
|
||||
mMessageSystem.ID = MongoService.getUniqueID(MMessageSystem.class);
|
||||
mMessageSystem.fromUID = super.UID;
|
||||
|
||||
for(InterfaceConstants.LANGS lang : InterfaceConstants.LANGS.values()){
|
||||
mMessageSystem.header.put(lang, sHeader);
|
||||
mMessageSystem.text.put(lang, sText);
|
||||
}
|
||||
|
||||
MongoService.save(mMessageSystem);
|
||||
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
ServerConstants.getEmailAddressSystemAdmin(),
|
||||
sHeader,
|
||||
sText);
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_FEEDBACK_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/cafe/new/{SID}/{CID}/{lang}/{header}/{text}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse newFeedbacks(@PathParam("SID") String SID,
|
||||
@PathParam("CID") int CID,
|
||||
@PathParam("lang") String sLang,
|
||||
@PathParam("header") String sHeader,
|
||||
@PathParam("text") String sText){
|
||||
|
||||
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
MUser mUser = MongoUserService.getUserProfile(UID);
|
||||
|
||||
MCafe mCafe = MongoService.getExceptionable(MCafe.class, CID);
|
||||
|
||||
MMessageCafe mMessageCafe = new MMessageCafe();
|
||||
mMessageCafe.ID = MongoService.getUniqueID(MMessageSystem.class);
|
||||
mMessageCafe.fromUID = super.UID;
|
||||
mMessageCafe.toCID = super.UID;
|
||||
|
||||
|
||||
for(InterfaceConstants.LANGS lang : InterfaceConstants.LANGS.values()){
|
||||
mMessageCafe.header.put(lang, sHeader);
|
||||
mMessageCafe.text.put(lang, sText);
|
||||
}
|
||||
|
||||
MongoService.save(mMessageCafe);
|
||||
|
||||
MUser mCafeOwner = MongoUserService.getUserProfile(mCafe.ownerID);
|
||||
|
||||
Mailer.sendMail(mUser.login, mCafeOwner.login, sHeader, sText);
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_FEEDBACK_NEW);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
71
kz_cafe_client/src/kz/cafe/client/rest/FENews.java
Normal file
71
kz_cafe_client/src/kz/cafe/client/rest/FENews.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
|
||||
@Path("/news")
|
||||
public class FENews extends FEAbstractService{
|
||||
// private static Log log = LogFactory.getLog(FESale.class);
|
||||
|
||||
private static final String LOG = "[JR SALE] ";
|
||||
|
||||
// private UserSession4 session = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FENews(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//Sales
|
||||
//---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public JRNewsListResponse getSales(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
JRNewsListResponse response = new JRNewsListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MNews mNews : (List<MNews>) MongoService.getListFrontEnd(MNews.class, lTime)){
|
||||
if(response.checkDeleted(mNews)){
|
||||
JRNewsListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mNews);
|
||||
|
||||
item.CID = mNews.CID;
|
||||
|
||||
item.date_notification = mNews.date_notification;
|
||||
item.main_screen = mNews.showMainScreen;
|
||||
item.news_screen = mNews.showNews;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRNewsListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_NEWS);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
63
kz_cafe_client/src/kz/cafe/client/rest/FEPhone.java
Normal file
63
kz_cafe_client/src/kz/cafe/client/rest/FEPhone.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
|
||||
@Path("/phone")
|
||||
public class FEPhone extends FEAbstractService{
|
||||
// private static Log log = LogFactory.getLog(FESale.class);
|
||||
|
||||
private static final String LOG = "[JR SALE] ";
|
||||
|
||||
|
||||
|
||||
public FEPhone(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//Phones
|
||||
//---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public JRPhoneListResponse getPhones(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
JRPhoneListResponse response = new JRPhoneListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MPhone mPhone : (List<MPhone>) MongoService.getListFrontEnd(MPhone.class, lTime)){
|
||||
if(response.checkDeleted(mPhone)){
|
||||
JRPhoneListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mPhone);
|
||||
|
||||
item.phone = mPhone.phone;
|
||||
item.city = mPhone.city;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRPhoneListResponse(e);
|
||||
}
|
||||
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
74
kz_cafe_client/src/kz/cafe/client/rest/FESale.java
Normal file
74
kz_cafe_client/src/kz/cafe/client/rest/FESale.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
|
||||
@Path("/sale")
|
||||
public class FESale extends FEAbstractService{
|
||||
// private static Log log = LogFactory.getLog(FESale.class);
|
||||
|
||||
private static final String LOG = "[JR SALE] ";
|
||||
|
||||
// private UserSession4 session = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FESale(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------
|
||||
//Sales
|
||||
//---------------------------------------------------------------------------------------------
|
||||
@GET
|
||||
@Path("/list/{LANG}/{TIME}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public JRSaleListResponse getSales(@PathParam("LANG") String sLang,
|
||||
@PathParam("TIME") long lTime){
|
||||
JRSaleListResponse response = new JRSaleListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MSale mSale : (List<MSale>) MongoService.getListFrontEnd(MSale.class, lTime)){
|
||||
|
||||
if(response.checkDeleted(mSale)){
|
||||
JRSaleListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mSale);
|
||||
|
||||
item.CID = mSale.CID;
|
||||
|
||||
item.date_from = mSale.date_from;
|
||||
item.date_notification = mSale.date_notification;
|
||||
item.date_to = mSale.date_to;
|
||||
item.main_screen = mSale.showMainScreen;
|
||||
item.news_screen = mSale.showNews;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRSaleListResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_SALES);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
59
kz_cafe_client/src/kz/cafe/client/rest/FESystem.java
Normal file
59
kz_cafe_client/src/kz/cafe/client/rest/FESystem.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.util.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
@Path("/system")
|
||||
public class FESystem extends FEAbstractService{
|
||||
//private static Log log = LogFactory.getLog(FEAdmin.class);
|
||||
|
||||
private static final String LOG = "[ADMIN] ";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FESystem(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@GET
|
||||
@Path("/messages/{LANG}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRDescriptorListResponse getI18N(@PathParam("LANG") String sLang){
|
||||
JRDescriptorListResponse response = new JRDescriptorListResponse();
|
||||
|
||||
try{
|
||||
InterfaceConstants.LANGS lang = validateLang(sLang);
|
||||
|
||||
for(MAbstractDescriptor mAbstractDescriptor :
|
||||
(List<MAbstractDescriptor>) MongoService.getListFrontEnd(MI18NClient.class, 0)){
|
||||
|
||||
if(response.checkDeleted(mAbstractDescriptor)){
|
||||
JRDescriptorListResponse.JMItem item = response.add();
|
||||
item.fillIn(lang, mAbstractDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e){
|
||||
response = new JRDescriptorListResponse(e);
|
||||
}
|
||||
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
425
kz_cafe_client/src/kz/cafe/client/rest/FEUser.java
Normal file
425
kz_cafe_client/src/kz/cafe/client/rest/FEUser.java
Normal file
@@ -0,0 +1,425 @@
|
||||
package kz.cafe.client.rest;
|
||||
|
||||
import java.io.*;
|
||||
import javax.servlet.http.*;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.client.rest.wrappers.*;
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.*;
|
||||
import kz.cafe.db.model.*;
|
||||
import kz.cafe.db.service.*;
|
||||
import kz.cafe.exceptions.*;
|
||||
import kz.cafe.security.*;
|
||||
import kz.cafe.utils.*;
|
||||
import org.apache.commons.fileupload.util.*;
|
||||
import org.apache.commons.logging.*;
|
||||
import com.google.code.morphia.query.*;
|
||||
|
||||
|
||||
@Path("/user")
|
||||
public class FEUser extends FEAbstractService{
|
||||
//private static Log log = LogFactory.getLog(FEUser.class);
|
||||
|
||||
private static final String LOG = "[JR USER] ";
|
||||
|
||||
// private UserSession4 session = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public FEUser(@Context HttpServletRequest hsr){
|
||||
super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/new/{LOGIN}/{PASSWORD}/{LANG}/{NAME}/{PHONE}/{CITY}/{GENDER}/{BIGTHDATE}/{OS}/{DEVICE}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRUserCreateResponse newUser(@PathParam("LOGIN") String sLogin,
|
||||
@PathParam("PASSWORD") String sPassword,
|
||||
@PathParam("LANG") final String sLang,
|
||||
@PathParam("NAME") String sName,
|
||||
@PathParam("PHONE") String sPhone,
|
||||
@PathParam("CITY") int iCity,
|
||||
@PathParam("GENDER") boolean bGender,
|
||||
@PathParam("BIGTHDATE") long lDate,
|
||||
@PathParam("OS") String OS,
|
||||
@PathParam("DEVICE") String DEVICE){
|
||||
|
||||
JRUserCreateResponse response = new JRUserCreateResponse();
|
||||
|
||||
try{
|
||||
final MUser mUser = MongoUserService.createEmptyProfile(sLogin);
|
||||
|
||||
mUser.login = sLogin;
|
||||
mUser.password = sPassword;
|
||||
|
||||
mUser.emailConfirmed = false;
|
||||
|
||||
mUser.lang = validateLang(sLang);
|
||||
|
||||
|
||||
mUser.name = sName;
|
||||
mUser.phone = sPhone;
|
||||
mUser.city = MongoService.getExceptionable(MCity.class, iCity).ID;
|
||||
|
||||
mUser.gender = bGender;
|
||||
|
||||
|
||||
mUser.birthdate = lDate;
|
||||
|
||||
|
||||
updateDeviceInfo(mUser, OS, DEVICE);
|
||||
uodateLoginTime(mUser);
|
||||
|
||||
|
||||
|
||||
|
||||
MongoUserService.save(mUser);
|
||||
|
||||
|
||||
final String sConfirmationCode = "" + new Long(mUser.login.hashCode()) * new Long(mUser.login.hashCode());
|
||||
MConfirmationCode mConfirmationCode = new MConfirmationCode();
|
||||
mConfirmationCode.code = sConfirmationCode;
|
||||
mConfirmationCode.UID = mUser.ID;
|
||||
MongoService.ds.save(mConfirmationCode);
|
||||
|
||||
|
||||
Thread threadSendConfirmationMail = new Thread(){
|
||||
private final Log log = LogFactory.getLog(Thread.class);
|
||||
private final String LOG = "[JR USER CONFIRMATION MAIL] ";
|
||||
|
||||
public void run() {
|
||||
try{
|
||||
InputStream is = ServerConstants.class.getResourceAsStream("/template_email_confirmation_" + sLang.toLowerCase() + ".txt");
|
||||
String sTemplate = Streams.asString(is);
|
||||
sTemplate = sTemplate.replaceAll("%email%", mUser.login);
|
||||
|
||||
sTemplate = sTemplate.replaceAll("%confirmation_link%", ServerConstants.getEmailConfirmationLink()+ "/" + sConfirmationCode);
|
||||
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
mUser.login,
|
||||
"Email Confirmation",
|
||||
sTemplate);
|
||||
}
|
||||
catch (IOException e){
|
||||
log.error(LOG, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
threadSendConfirmationMail.start();
|
||||
|
||||
|
||||
long SID = Sessions.open(mUser.ID);
|
||||
|
||||
response.SID = super.long2sid(SID);
|
||||
response.UID = mUser.ID;
|
||||
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_USER_NEW);
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRUserCreateResponse(e);
|
||||
}
|
||||
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/email/confirm/{CODE}")
|
||||
@Produces({ MediaType.TEXT_HTML})
|
||||
public String confirmEmail(@PathParam("CODE") String sCode){
|
||||
MConfirmationCode mConfirmationCode = MongoService.ds.find(MConfirmationCode.class, MConfirmationCode.F_CODE, sCode).get();
|
||||
|
||||
if(mConfirmationCode == null){
|
||||
return "wrong code";
|
||||
}
|
||||
else{
|
||||
Query<MUser> q =MongoService.ds.createQuery(MUser.class).filter(MUser.F_UID, mConfirmationCode.UID);
|
||||
UpdateOperations<MUser> uOps = MongoService.ds.createUpdateOperations(MUser.class).set(MUser.F_EMAIL_CONFIRMED, true);
|
||||
MongoService.ds.findAndModify(q, uOps);
|
||||
|
||||
|
||||
MongoService.ds.delete(MongoService.ds.createQuery(MConfirmationCode.class).filter(MConfirmationCode.F_CODE, mConfirmationCode.code));
|
||||
|
||||
|
||||
return "ok, confirmed.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/login/{LOGIN}/{PASSWORD}/{OS}/{DEVICE}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRUserLoginResponse login(@PathParam("LOGIN") String sLogin,
|
||||
@PathParam("PASSWORD") String sPassword,
|
||||
@PathParam("OS") String OS,
|
||||
@PathParam("DEVICE") String DEVICE){
|
||||
JRUserLoginResponse response = new JRUserLoginResponse();
|
||||
|
||||
try{
|
||||
MUser mUser = MongoUserService.getUserProfile(sLogin);
|
||||
|
||||
if(mUser.password.equals(sPassword)){
|
||||
long SID = Sessions.open(mUser.ID);
|
||||
|
||||
response.UID = mUser.ID;
|
||||
response.SID = super.long2sid(SID);
|
||||
|
||||
updateDeviceInfo(mUser, OS, DEVICE);
|
||||
uodateLoginTime(mUser);
|
||||
|
||||
MongoUserService.save(mUser);
|
||||
updateStatistic(MAbstractStatistics.F_LOGIN_SUCCESS);
|
||||
}
|
||||
else{
|
||||
throw new LoginFailedException(sLogin, sPassword);
|
||||
}
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRUserLoginResponse(e);
|
||||
}
|
||||
|
||||
updateStatistic(MAbstractStatistics.F_LOGINS);
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/remove/{SID}/{PARAM}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRUserCreateResponse updateUserRemoveValue(@PathParam("SID") String SID,
|
||||
@PathParam("PARAM") String sParam){
|
||||
return updateUser(SID, sParam, "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/update/{SID}/{PARAM}/{VALUE}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRUserCreateResponse updateUser(@PathParam("SID") String SID,
|
||||
@PathParam("PARAM") String sParam,
|
||||
@PathParam("VALUE") String sValue){
|
||||
|
||||
JRUserCreateResponse response = new JRUserCreateResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MUser mUser = MongoUserService.getUserProfile(UID);
|
||||
|
||||
|
||||
switch(sParam){
|
||||
case "password":{
|
||||
mUser.password = sValue;
|
||||
|
||||
break;
|
||||
}
|
||||
case "lang":{
|
||||
mUser.lang = validateLang(sValue);
|
||||
|
||||
break;
|
||||
}
|
||||
case "name":{
|
||||
mUser.name = sValue;
|
||||
|
||||
break;
|
||||
}
|
||||
case "phone":{
|
||||
mUser.phone = sValue;
|
||||
|
||||
break;
|
||||
}
|
||||
case "city":{
|
||||
if("".equals(sValue)) {
|
||||
mUser.city = null;
|
||||
}
|
||||
else{
|
||||
mUser.city = MongoService.getExceptionable(MCity.class, Integer.parseInt(sValue)).ID;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "avatar":{
|
||||
if("".equals(sValue)){
|
||||
mUser.image = null;
|
||||
}
|
||||
else{
|
||||
mUser.image = sValue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "gender":{
|
||||
mUser.gender = Boolean.parseBoolean(sValue);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "birthday":{
|
||||
mUser.birthdate = Long.parseLong(sValue);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MongoUserService.save(mUser);
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRUserCreateResponse(e);
|
||||
}
|
||||
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/profile/{SID}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JRUserProfileResponse getProfile(@PathParam("SID") String SID){
|
||||
|
||||
JRUserProfileResponse response = new JRUserProfileResponse();
|
||||
|
||||
try{
|
||||
checkSession(SID);
|
||||
|
||||
MUser mUser = MongoUserService.getUserProfile(super.UID);
|
||||
|
||||
response.birthdate = mUser.birthdate;
|
||||
response.dateLatestLogin = mUser.dateLatestLogin;
|
||||
response.dateRegistration = mUser.dateRegistration;
|
||||
response.gender = mUser.gender;
|
||||
response.lang = mUser.lang.name();
|
||||
response.name = mUser.name;
|
||||
response.phone = mUser.phone;
|
||||
response.city = mUser.city;
|
||||
response.avatar = mUser.image;
|
||||
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JRUserProfileResponse(e);
|
||||
}
|
||||
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/password/recovery/{lang}/{email}")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public JREmptyResponse password(@PathParam("lang") String sLang,
|
||||
@PathParam("email") String sEmail){
|
||||
|
||||
JREmptyResponse response = new JREmptyResponse();
|
||||
|
||||
try{
|
||||
checkLanguage(sLang);
|
||||
|
||||
MUser mUser = MongoUserService.getUserProfile(sEmail);
|
||||
|
||||
InputStream is = ServerConstants.class.getResourceAsStream("/template_password_recovery_" + sLang.toLowerCase() + ".txt");
|
||||
String sTemplate = Streams.asString(is);
|
||||
sTemplate = sTemplate.replaceAll("%login%", mUser.login);
|
||||
sTemplate = sTemplate.replaceAll("%password%", mUser.password);
|
||||
|
||||
Mailer.sendMail(ServerConstants.getRobot(),
|
||||
sEmail,
|
||||
"password",
|
||||
sTemplate);
|
||||
}
|
||||
catch(Throwable e){
|
||||
response = new JREmptyResponse(e);
|
||||
}
|
||||
|
||||
super.responseTime(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static void updateDeviceInfo(MUser mUser, String OS, String DEVICE){
|
||||
MUser.Device device = new MUser.Device(DEVICE, OS);
|
||||
|
||||
mUser.device = device;
|
||||
|
||||
if(mUser.devices.contains(device)){
|
||||
}
|
||||
else{
|
||||
mUser.devices.add(device);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static void uodateLoginTime(MUser mUser){
|
||||
mUser.dateLatestLogin = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package kz.cafe.client.rest.wrappers;
|
||||
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
public class JMAbstractDataElement{
|
||||
|
||||
public Integer ID;
|
||||
public Long created;
|
||||
public Long updated;
|
||||
public String deleted;
|
||||
|
||||
|
||||
|
||||
public void fillIn(MAbstractEditableDataElement mAbstractDataElement){
|
||||
this.ID = mAbstractDataElement.ID;
|
||||
this.created = mAbstractDataElement.created;
|
||||
this.updated = mAbstractDataElement.updated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String checkIsImageEmpty(String sImage){
|
||||
if(sImage == null || InterfaceConstants.EMPTY_IMAGE.equalsIgnoreCase(sImage)){
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return sImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package kz.cafe.client.rest.wrappers;
|
||||
|
||||
import kz.cafe.constants.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
public class JMAbstractDescriptor extends JMAbstractDataElement{
|
||||
|
||||
public String name;
|
||||
public String description;
|
||||
public String image;
|
||||
public int order;
|
||||
|
||||
|
||||
|
||||
public void fillIn(InterfaceConstants.LANGS lang, MAbstractDescriptor mAbstractDescriptor){
|
||||
super.fillIn(mAbstractDescriptor);
|
||||
|
||||
this.name = mAbstractDescriptor.name.get(lang);
|
||||
this.description = mAbstractDescriptor.description.get(lang);
|
||||
this.image = checkIsImageEmpty(mAbstractDescriptor.image);
|
||||
this.order = mAbstractDescriptor.order;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package kz.cafe.client.rest.wrappers;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import kz.cafe.client.*;
|
||||
import kz.cafe.db.model.*;
|
||||
|
||||
public class JRAbstractDeleteableResponse extends JRAbstractResponse{
|
||||
|
||||
private StringBuilder sbDeleted = new StringBuilder();
|
||||
|
||||
@XmlElement(name="deleted")
|
||||
public String getDeleted(){
|
||||
if(sbDeleted.length() == 0){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
return sbDeleted.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean checkDeleted(MAbstractEditableDataElement mAbstractEditableDataElement){
|
||||
if(mAbstractEditableDataElement.deleted || !mAbstractEditableDataElement.published){
|
||||
if(sbDeleted.length() > 0){
|
||||
sbDeleted.append(",");
|
||||
}
|
||||
sbDeleted.append(mAbstractEditableDataElement.ID);
|
||||
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public JRAbstractDeleteableResponse(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public JRAbstractDeleteableResponse(Throwable e){
|
||||
super(e);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package kz.cafe.client.rest.wrappers;
|
||||
|
||||
import java.util.*;
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlRootElement(name="response")
|
||||
public class JRCafeImageListResponse extends JRAbstractDeleteableResponse{
|
||||
|
||||
@XmlElementWrapper(name="list")
|
||||
@XmlElement(name="item")
|
||||
public List<JMItem> list = new ArrayList<JMItem>();
|
||||
|
||||
|
||||
public JMItem add(){
|
||||
JMItem jmItem = new JMItem();
|
||||
list.add(jmItem);
|
||||
|
||||
return jmItem;
|
||||
}
|
||||
|
||||
|
||||
public static class JMItem extends JMAbstractDescriptor{
|
||||
public Integer CID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JRCafeImageListResponse(){
|
||||
}
|
||||
|
||||
|
||||
public JRCafeImageListResponse(Throwable e){
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package kz.cafe.client.rest.wrappers;
|
||||
|
||||
import java.util.*;
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlRootElement(name="response")
|
||||
public class JRCafeListResponse extends JRAbstractDeleteableResponse{
|
||||
|
||||
@XmlElementWrapper(name="list")
|
||||
@XmlElement(name="item")
|
||||
public List<JMItem> list = new ArrayList<JMItem>();
|
||||
|
||||
|
||||
public JMItem add(){
|
||||
JMItem jmItem = new JMItem();
|
||||
list.add(jmItem);
|
||||
|
||||
return jmItem;
|
||||
}
|
||||
|
||||
|
||||
public static class JMItem extends JMAbstractDescriptor{
|
||||
public Integer type;
|
||||
public Integer rate;
|
||||
public Integer price;
|
||||
public int timeOpen;
|
||||
public int timeClose;
|
||||
public int timeOpenWeekend;
|
||||
public int timeCloseWeekend;
|
||||
public String phone;
|
||||
public String address;
|
||||
public String service;
|
||||
public String coordinates;
|
||||
public boolean hasDelivery;
|
||||
public boolean hasReservation;
|
||||
public String types;
|
||||
public String requirements;
|
||||
public String cuisines;
|
||||
public Integer tables_total;
|
||||
public Integer tables_free;
|
||||
public Integer bill_average_min;
|
||||
public Integer bill_average_max;
|
||||
public Integer city;
|
||||
public int timeCloseMo;
|
||||
public int timeOpenMo;
|
||||
public int timeCloseTu;
|
||||
public int timeOpenTu;
|
||||
public int timeCloseWe;
|
||||
public int timeOpenWe;
|
||||
public int timeCloseTh;
|
||||
public int timeOpenTh;
|
||||
public int timeCloseFr;
|
||||
public int timeOpenFr;
|
||||
public int timeCloseSa;
|
||||
public int timeOpenSa;
|
||||
public int timeCloseSu;
|
||||
public int timeOpenSu;
|
||||
public Integer timeOrdersFrom;
|
||||
public Integer timeOrdersTo;
|
||||
public Integer timeReservationFrom;
|
||||
public Integer timeReservationTo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JRCafeListResponse(){
|
||||
}
|
||||
|
||||
|
||||
public JRCafeListResponse(Throwable e){
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package kz.cafe.client.rest.wrappers;
|
||||
|
||||
import java.util.*;
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlRootElement(name="response")
|
||||
public class JRCityListResponse extends JRAbstractDeleteableResponse{
|
||||
|
||||
@XmlElementWrapper(name="list")
|
||||
@XmlElement(name="item")
|
||||
public List<JMItem> list = new ArrayList<JMItem>();
|
||||
|
||||
|
||||
public JMItem add(){
|
||||
JMItem jmItem = new JMItem();
|
||||
list.add(jmItem);
|
||||
|
||||
return jmItem;
|
||||
}
|
||||
|
||||
|
||||
public static class JMItem extends JMAbstractDescriptor{
|
||||
public Integer GMT;
|
||||
public boolean hasCafe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JRCityListResponse(){
|
||||
}
|
||||
|
||||
|
||||
public JRCityListResponse(Throwable e){
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package kz.cafe.client.rest.wrappers;
|
||||
|
||||
import java.util.*;
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
@XmlRootElement(name="response")
|
||||
public class JRCourseListResponse extends JRAbstractDeleteableResponse{
|
||||
|
||||
@XmlElementWrapper(name="list")
|
||||
@XmlElement(name="item")
|
||||
public List<JMItem> list = new ArrayList<JMItem>();
|
||||
|
||||
|
||||
public JMItem add(){
|
||||
JMItem jmItem = new JMItem();
|
||||
list.add(jmItem);
|
||||
|
||||
return jmItem;
|
||||
}
|
||||
|
||||
|
||||
public static class JMItem extends JMAbstractDescriptor{
|
||||
public Integer category;
|
||||
public Integer CID;
|
||||
public Integer price;
|
||||
public String ingredients;
|
||||
public String weight;
|
||||
public boolean delivery;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JRCourseListResponse(){
|
||||
}
|
||||
|
||||
|
||||
public JRCourseListResponse(Throwable e){
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user