package it.acxent.dm; import it.acxent.db.ApplParmFull; import it.acxent.db.DBAdapter; import it.acxent.db.ResParm; import it.acxent.db.WcString; import it.acxent.util.StringTokenizer; import it.acxent.util.Vectumerator; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.SQLException; import org.json.JSONArray; import org.json.JSONObject; public class FaceDetectionMethod extends DBAdapter implements Serializable { private static final long serialVersionUID = 1705937095434L; private long id_faceDetectionMethod; private long codice; private String descrizione; private long flgDetectionType; private String descrizioneLunga; private String pathModello; private long flgBtn; public static final long FACE_DETECTION_TYPE_OCV = 0L; public static final long FACE_DETECTION_TYPE_GOOGLE = 1L; public static final long FACE_DETECTION_TYPE_YUNET = 2L; public static final long FACE_DETECT_METHOD_H_DEFAULT = 0L; public static final long FACE_DETECT_METHOD_H_ALT = 1L; public static final long FACE_DETECT_METHOD_H_ALT2 = 2L; public static final long FACE_DETECT_METHOD_H_ALT_TREE = 3L; public static final long FACE_DETECT_METHOD_L_DEFAULT = 4L; public static final long FACE_DETECT_METHOD_L_IMPROVED = 5L; public static final long FACE_DETECT_METHOD_YUNET = 20L; public static final long FACE_DETECT_METHOD_GOOGLE_VISION = 99L; public static final String getDetectionType(long l_flgDetectionType) { if (l_flgDetectionType == 0L) return "Open CV"; if (l_flgDetectionType == 1L) return "Google Vision"; if (l_flgDetectionType == 2L) return "Yunet zoo"; return ""; } public final String getDetectionType() { return getDetectionType(getFlgDetectionType()); } public FaceDetectionMethod(ApplParmFull newApplParmFull) { super(newApplParmFull); } public FaceDetectionMethod() {} public void setId_faceDetectionMethod(long newId_faceDetectionMethod) { this.id_faceDetectionMethod = newId_faceDetectionMethod; } public void setCodice(long newCodice) { this.codice = newCodice; } public void setDescrizione(String newDescrizione) { this.descrizione = newDescrizione; } public void setFlgDetectionType(long newFlgDectectionType) { this.flgDetectionType = newFlgDectectionType; } public void setDescrizioneLunga(String newDescrizioneLunga) { this.descrizioneLunga = newDescrizioneLunga; } public void setPathModello(String newPathModello) { this.pathModello = newPathModello; } public long getId_faceDetectionMethod() { return this.id_faceDetectionMethod; } public long getCodice() { return this.codice; } public String getDescrizione() { return (this.descrizione == null) ? "" : this.descrizione.trim(); } public long getFlgDetectionType() { return this.flgDetectionType; } public String getDescrizioneLunga() { return (this.descrizioneLunga == null) ? "" : this.descrizioneLunga.trim(); } public String getPathModello() { return (this.pathModello == null) ? "" : this.pathModello.trim(); } public String getApiKey() { return getPathModello(); } protected ResParm checkDeleteCascade() { return new ResParm(true); } protected void deleteCascade() {} public Vectumerator findByBtn() { String s_Sql_Find = "select A.* from FACE_DETECTION_METHOD AS A"; String s_Sql_Order = " order by A.codice"; WcString wc = new WcString(); wc.addWc("A.flgBtn=1"); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); return findRows(stmt); } catch (SQLException e) { removeCPConnection(); handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public void findByCodice(long l_codice) { String s_Sql_Find = "select A.* from FACE_DETECTION_METHOD AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); if (l_codice == 0L) { wc.addWc("(A.codice=0 or A.codice is null)"); } else { wc.addWc("A.codice=" + l_codice); } try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); findFirstRecord(stmt); } catch (SQLException e) { removeCPConnection(); handleDebug(e); } } public ResParm syncJson(JSONArray jaFdm) { ResParm rp = new ResParm(); boolean debug = false; if (debug) System.out.println("syncJson:\n" + jaFdm.toString()); FaceDetectionMethod row = new FaceDetectionMethod(getApFull()); for (int i = 0; i < jaFdm.length(); i++) { JSONObject jRow = jaFdm.getJSONObject(i); if (debug) System.out.println("syncJson: codice " + jRow.getLong("codice") + " desc: " + jRow.getString("descrizione")); row.findByCodice(jRow.getLong("codice")); row.setCodice(jRow.getLong("codice")); row.setFlgDetectionType(jRow.getLong("flgDetectionType")); row.setDescrizione(jRow.getString("descrizione")); row.setDescrizioneLunga(jRow.getString("descrizioneLunga")); row.save(); } return rp; } protected String sqlStringfindAll() { return "select A.* from FACE_DETECTION_METHOD AS A order by codice"; } public long getFlgBtn() { return this.flgBtn; } public void setFlgBtn(long flgBtn) { this.flgBtn = flgBtn; } public Vectumerator findByCR(FaceDetectionMethodCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from FACE_DETECTION_METHOD AS A"; String s_Sql_Order = " order by codice"; WcString wc = new WcString(); if (!CR.getSearchTxt().trim().isEmpty()) { StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " "); StringBuffer txt = new StringBuffer("("); while (st.hasMoreTokens()) { String token = st.nextToken(); txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')"); if (st.hasMoreTokens()) txt.append(" and "); } txt.append(")"); wc.addWc(txt.toString()); } 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; } } }