제출된 데이터에 대해 쿼리할 수 있으려면 제출된 양식과 연결된 JSON 스키마를 저장해야 합니다. JSON 스키마는 쿼리 빌더에서 쿼리를 빌드하는 데 사용됩니다.
적응형 양식이 제출되면 연결된 JSON 스키마가 데이터베이스에 있는지 확인합니다. JSON 스키마가 존재하지 않는 경우 JSON 스키마를 가져와 적절한 테이블에 스키마를 저장합니다. 또한 양식 이름을 JSON 스키마와 연결합니다. 다음 스크린샷은 JSON 스키마가 저장된 테이블을 보여 줍니다.
public String getJSONSchema(String afPath) {
// TODO Auto-generated method stub
afPath = afPath.replaceAll("/content/dam/formsanddocuments/", "/content/forms/af/");
Resource afResource = getResolver.getServiceResolver().getResource(afPath + "/jcr:content/guideContainer");
javax.jcr.Node resNode = afResource.adaptTo(Node.class);
String schemaNode = null;
try {
schemaNode = resNode.getProperty("schemaRef").getString();
} catch (ValueFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PathNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (schemaNode.startsWith("/content/dam")) {
log.debug("The schema is in the dam");
afResource = getResolver.getServiceResolver()
.getResource(schemaNode + "/jcr:content/renditions/original/jcr:content");
resNode = afResource.adaptTo(Node.class);
InputStream jsonSchemaStream = null;
try {
jsonSchemaStream = resNode.getProperty("jcr:data").getBinary().getStream();
Charset charset = StandardCharsets.UTF_8;
String jasonSchemaString = IOUtils.toString(jsonSchemaStream, charset);
log.debug("The Schema is " + jasonSchemaString);
return jasonSchemaString;
} catch (ValueFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PathNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (schemaNode.startsWith("/assets")) {
afResource = getResolver.getServiceResolver()
.getResource(afPath + "/jcr:content/guideContainer/" + schemaNode + "/jcr:content");
resNode = afResource.adaptTo(Node.class);
InputStream jsonSchemaStream = null;
try {
jsonSchemaStream = resNode.getProperty("jcr:data").getBinary().getStream();
Charset charset = StandardCharsets.UTF_8;
String jasonSchemaString = IOUtils.toString(jsonSchemaStream, charset);
log.debug("The Schema is " + jasonSchemaString);
return jasonSchemaString;
} catch (ValueFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PathNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
적응형 양식을 작성할 때 저장소의 JSON 스키마를 사용하거나 JSON 스키마를 업로드할 수 있습니다. 위 코드는 두 경우 모두에 대해 작동합니다.
가져온 스키마는 표준 JDBC 작업을 사용하여 데이터베이스에 저장됩니다. 다음 코드는 데이터베이스에 스키마를 삽입합니다
public void insertJsonSchema(JSONObject jsonSchema, String afForm) {
log.debug("$$$$ in insert Schema" + afForm);
log.debug("$$$$$ The jsonSchema is " + jsonSchema);
Connection con = getConnection();
log.debug("$$$$ got connection is insertJsonSchema");
String insertTableSQL = "INSERT INTO leads.jsonschemas(jsonschema,formname) VALUES(?,?)";
PreparedStatement pstmt = null;
try {
// org.json.JSONObject jsonSchemaObj = new
// org.json.JSONObject(jsonSchema);
pstmt = con.prepareStatement(insertTableSQL);
pstmt.setString(1, jsonSchema.toString());
pstmt.setString(2, afForm);
log.debug("Executing the insert json schema statment " + pstmt.executeUpdate());
con.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
요약하자면, 우리는 지금까지 다음과 같은 일을 했다
다음 단계는 QueryBuilder를 사용하여 JSON 스키마를 기준으로 검색할 필드를 표시하는 것입니다