Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private GeneratedClass generateResource(MetaModule module) {
clazz.addImport("net.anotheria.anoprise.metafactory.MetaFactoryException");
clazz.addImport("io.swagger.v3.oas.annotations.Operation");
clazz.addImport("io.swagger.v3.oas.annotations.tags.Tag");
clazz.addImport("org.codehaus.jettison.json.JSONArray");
clazz.addImport("net.anotheria.anosite.gen.shared.util.ParserUtilService");
clazz.addImport(ReplyObject.class);
clazz.addImport(ServiceGenerator.getInterfaceImport(module));
clazz.addImport(ServiceGenerator.getExceptionImport(module));
Expand Down Expand Up @@ -194,6 +196,24 @@ private void generateDocumentCRUD(MetaDocument doc, String serviceException, Con
appendStatement("return ReplyObject.error(e)");
closeBlockNEW();
closeBlockNEW();
emptyline();

//TRANSFER
appendString("@POST");
appendString("@Path(\"" + docPath + "/transfer\")");
appendString("@Consumes(\"application/json;charset=utf-8\")");
appendString("@Produces(MediaType.APPLICATION_JSON)");
appendString("@Operation(summary = \"Create new objects according to transfer " + docName + " process\")");
appendString("public ReplyObject transfer" + docName + "AndLinkedObjects(String input) {");
increaseIdent();
openTry();
appendStatement("ParserUtilService.getInstance().addToQueueParsingDocuments(new JSONArray(input))");
appendCatch("Exception");
appendStatement("LOG.error(\"Unable to parsing transferred objects for " + docName + "\", e)");
appendStatement("return ReplyObject.error(e)");
closeBlockNEW();
appendStatement("return ReplyObject.success()");
closeBlockNEW();
}

private void appendCopyVOToDoc(MetaDocument doc, String voVar, String docVar, Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2051,14 +2051,16 @@ private GeneratedClass generateTransferAction(MetaModuleSection section) {
clazz.addImport("jakarta.ws.rs.core.MediaType");
clazz.addImport("jakarta.ws.rs.core.Response");
clazz.addImport("net.anotheria.anosite.util.staticutil.JerseyClientUtil");
clazz.addImport("org.codehaus.jettison.json.JSONArray");
clazz.addImport("java.util.HashSet");

clazz.setName(getTransferActionName(section));
clazz.setParent(getBaseActionName(section));

startClassBody();
emptyline();
appendStatement("private static final String ERROR = \"error\"");
appendStatement("private static final String REST_PATH = \"/api/" + module.getName().toLowerCase() + "/" + doc.getName().toLowerCase() + "/\"");
appendStatement("private static final String REST_PATH = \"/asg-api/" + module.getName().toLowerCase() + "/" + doc.getName().toLowerCase() + "/\"");
emptyline();
appendStatement("private final DocumentTransferConfig config = DocumentTransferConfig.getInstance()");
appendStatement("private final ObjectMapper mapper = new ObjectMapper()");
Expand Down Expand Up @@ -2093,31 +2095,20 @@ private void generateTransferActionMethod(GeneratedClass clazz, MetaModuleSectio
emptyline();

appendStatement("String id = getStringParameter(req, PARAM_ID)");
appendStatement(doc.getName() + " doc");
appendStatement("JSONArray data = new JSONArray()");
openTry();
appendStatement("doc = " + getServiceGetterCall(section.getModule()) + ".get" + doc.getName() + "(id)");
appendStatement(getServiceGetterCall(section.getModule()) + ".fetch" + doc.getName() + "(id, new HashSet<>(), data)");
appendCatch(ServiceGenerator.getExceptionName(section.getModule()));
appendStatement("response.addError(ERROR, \"Failed to load document: \" + e.getMessage())");
appendStatement("writeTextToResponse(res, response)");
appendStatement("return null");
closeBlockNEW();
emptyline();

appendStatement(voName + " vo = " + voName + ".from(doc)");
appendStatement("String body");
openTry();
appendStatement("body = mapper.writeValueAsString(vo)");
appendCatch("Exception");
appendStatement("response.addError(ERROR, \"Failed to serialize document: \" + e.getMessage())");
appendStatement("writeTextToResponse(res, response)");
appendStatement("return null");
closeBlockNEW();
emptyline();

appendStatement("Client client = JerseyClientUtil.getClientInstance()");
appendString("for (String domain : config.getDomains()) {");
increaseIdent();
appendStatement("Response clientResponse = client.target(domain + REST_PATH + id).request(MediaType.APPLICATION_JSON).put(Entity.entity(body, MediaType.APPLICATION_JSON))");
appendStatement("Response clientResponse = client.target(domain + REST_PATH + \"transfer\").request(MediaType.APPLICATION_JSON).post(Entity.entity(data.toString(), MediaType.APPLICATION_JSON))");
openTry();
appendStatement("ReplyObject reply = mapper.readValue(clientResponse.readEntity(String.class), ReplyObject.class)");
appendString("if (!reply.isSuccess()) {");
Expand Down