Regalamiunsorriso/decompiled-libs/www/acxent-face-1.0.0/it/acxent/face/fr/FotoRequest.java

228 lines
6.5 KiB
Java

package it.acxent.face.fr;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import it.acxent.db.ResParm;
import it.acxent.db.WcString;
import it.acxent.dm.FaceDetectionMethod;
import it.acxent.util.Vectumerator;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class FotoRequest extends DBAdapter implements Serializable {
private static final long serialVersionUID = 1700680369881L;
public static final long REQUEST_TYPE_DETECT_ERROR = -1L;
public static final long REQUEST_TYPE_DETECT_ALL = 0L;
public static final long REQUEST_TYPE_DETECT_FACE = 1L;
public static final long REQUEST_TYPE_DETECT_NUMBERS = 3L;
private long id_fotoRequest;
private long id_users;
private String md5;
private String json;
private long nRichieste;
private FaceDetectionMethod faceDetectionMethod;
private Users users;
private long faceDetectionMethodCode;
private long flgRequestType;
public FotoRequest(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public FotoRequest() {}
public static final String getRequestType(long l_flgRequestType) {
if (l_flgRequestType == 0L)
return "Completa";
if (l_flgRequestType == 1L)
return "Completa";
if (l_flgRequestType == 3L)
return "Completa";
return "";
}
public void setId_fotoRequest(long newId_fotoRequest) {
this.id_fotoRequest = newId_fotoRequest;
}
public void setId_users(long newId_users) {
this.id_users = newId_users;
setUsers(null);
}
public void setMd5(String newMd5) {
this.md5 = newMd5;
}
public void setJson(String newJsonCompleto) {
this.json = newJsonCompleto;
}
public void setNRichieste(long newNRichieste) {
this.nRichieste = newNRichieste;
}
public long getId_fotoRequest() {
return this.id_fotoRequest;
}
public long getId_users() {
return this.id_users;
}
public String getMd5() {
return (this.md5 == null) ? "" : this.md5.trim();
}
public String getJson() {
if (hasDetectFacesResponseFaces(this.json))
return this.json.trim();
return "";
}
public long getNRichieste() {
return this.nRichieste;
}
public void setUsers(Users newUsers) {
this.users = newUsers;
}
public Users getUsers() {
this.users = (Users)getSecondaryObject((DBAdapter)this.users, Users.class, getId_users());
return this.users;
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
protected void deleteCascade() {}
public Vectumerator<FotoRequest> findByCR(FotoRequestCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from FOTO_REQUEST AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
if (CR.getId_users() > 0L)
wc.addWc("A.id_users=" + CR.getId_users());
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return findRows(stmt, pageNumber, pageRows);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return AB_EMPTY_VECTUMERATOR;
}
}
public Vectumerator<FotoRequest> findByUsers(long l_id_users, int pageNumber, int pageRows) {
FotoRequestCR CR = new FotoRequestCR();
CR.setId_users(l_id_users);
return findByCR(CR, pageNumber, pageRows);
}
public void findByUserMd5DetectionmethodRequesttype(long l_id_user, String l_md5, long l_flgFaceDetectionMethod, long l_flgRequestType) {
String s_Sql_Find = "select A.* from FOTO_REQUEST AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc("A.id_users=" + l_id_user);
wc.addWc("A.md5='" + l_md5 + "'");
if (l_flgRequestType == 0L) {
wc.addWc("(A.flgRequestType is null || A.flgRequestType=0) ");
} else {
wc.addWc("A.flgRequestType=" + l_flgRequestType);
}
if (l_flgFaceDetectionMethod == 0L) {
wc.addWc("(A.faceDetectionMethodCode is null || A.faceDetectionMethodCode=0) ");
} else {
wc.addWc("A.faceDetectionMethodCode=" + l_flgFaceDetectionMethod);
}
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
findFirstRecord(stmt);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
}
}
public static boolean hasDetectFacesResponseFaces(String jsonString) {
if (jsonString == null || jsonString.isEmpty())
return false;
try {
JsonElement parsed = JsonParser.parseString(jsonString);
if (!parsed.isJsonObject())
return false;
JsonObject json = parsed.getAsJsonObject();
if (json.has("responses")) {
JsonArray responses = json.getAsJsonArray("responses");
if (responses.size() > 0) {
JsonObject response = responses.get(0).getAsJsonObject().getAsJsonObject("response");
JsonArray annotations = response.getAsJsonArray("faceAnnotations");
return (annotations != null && annotations.size() > 0);
}
}
} catch (JsonSyntaxException e) {
return false;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public void setJson(long l_flgRequestType, String l_json) {
setFlgRequestType(l_flgRequestType);
setJson(l_json);
}
public void addRichiesta() {
setNRichieste(getNRichieste() + 1L);
}
public final FaceDetectionMethod getFaceDetectionMethod() {
if (this.faceDetectionMethod == null && getFaceDetectionMethodCode() >= 0L) {
this.faceDetectionMethod = new FaceDetectionMethod(getApFull());
this.faceDetectionMethod.findByCodice(getFaceDetectionMethodCode());
}
return (this.faceDetectionMethod == null) ? new FaceDetectionMethod(getApFull()) : this.faceDetectionMethod;
}
public long getFaceDetectionMethodCode() {
return this.faceDetectionMethodCode;
}
public void setFaceDetectionMethodCode(long flgFaceDetectionMethod) {
this.faceDetectionMethodCode = flgFaceDetectionMethod;
}
public long getFlgRequestType() {
return this.flgRequestType;
}
public void setFlgRequestType(long flgRequestType) {
this.flgRequestType = flgRequestType;
}
public void setFaceDetectionMethod(FaceDetectionMethod faceDetectionMethod) {
this.faceDetectionMethod = faceDetectionMethod;
}
}