1

I have following 2 classes. The primary class is Aloscalculation, which has a variable finalOutput which contains certain values.DataSet<Tuple4<String, String, Double, String>> finalOutput. The value is tried to be inserted into postgresql. The variable connectionValues is having the json and it has various parameters like username,password,drivername which is received from a hashmap called outermap. From Writealos I am able to send the row object which is tried to be inserted in in Aloscalculation. But I am unable to send variable connectionvalues to set the drivername,password,url, and username. Please suggest me how to do it. The values like org_metric_result, org_metric_orgid are calculated accordingly.

I have now edited the code in a new way to solve the problem. But now the new issue is in Writealos method if the match doesnt takes place i get an empty object returned. Due which while Database insertion i get an exception saying Null value is being formed and cannot be inserted. Please anyone can solve this error?

    public class Writealos implements MapFunction<Tuple4<String, String, Double, String>, Row> 
    {
        @Autowired
        private Tenantresource outermap;
        public Row map(Tuple4<String, String, Double, String> arg0)throws Exception
        {
            if(arg0.f0.equals(currentKey))
            {
               Row obj = new Row(7);
               String string = RandomStringUtils.randomAlphanumeric(32);
               obj.setField(0, string);
               obj.setField(1, alos);
               obj.setField(2, org_metric_result.toString());
               obj.setField(3, Start_Date.toString());
               obj.setField(4, End_Date.toString());
               obj.setField(5, Execution_Date.toString());
               obj.setField(6, org_metric_orgid);
         }
            return obj; 
        }
    }

    public class Aloscalculation
    {
        @Autowired
    private static Tenantresource outermap;
        public static void calculateAlos(Fhirresource fhir_resource ) throws Exception 
        {
            String query = "insert into reports (org_metric_id,org_metric_topic, org_metric_result, org_metric_from, org_metric_to, org_metric_executed_on, org_metric_orgid) values (?,?,cast(? as json),cast(? as timestamp),cast(? as timestamp),cast(? as timestamp),?)";
         for(String currentKey : outermap.tenantresourcereturn().keySet()) 
         { 
             JSONObject connection =new JSONObject( outermap.tenantresourcereturn().get(currentKey));
             System.out.println(currentKey);
             String url=connection.getString("jdbc_url")+":"+connection.getString("port")+"/"+connection.getString("db_name");
             System.out.println(url);
            finaloutput.map(new Writealos(fhir_resource,currentKey))
                .output(JDBCOutputFormat.buildJDBCOutputFormat()
                .setDrivername()
                .setDBUrl()
                .setUsername()
                .setPassword()
                .setQuery(query)
                .finish());
        }
    }

1 Answers1

0

How are you exposing public Row map(Tuple4<String, String, Double, String> arg0), is it through a service. Spring provides an annotation @ResponseBody. You need to have a matching POJO and spring will take care of the conversion. Secondly, why are you not planning to use any ORM tool (Hibernate, Ibatis etc), it can ease your CRUD operations.

How does the Spring @ResponseBody annotation work in this RESTful application example?

Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57