Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

SR: #43. Improved & simplified interface and workflow and data services #147

Merged
merged 1 commit into from
Sep 7, 2016
Merged
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
21 changes: 19 additions & 2 deletions opensrp-core/src/main/java/org/opensrp/domain/ErrorTrace.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.opensrp.domain;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.codehaus.jackson.annotate.JsonProperty;
import org.ektorp.support.TypeDiscriminator;
Expand All @@ -9,7 +11,7 @@
/**
* @author [email protected] Created on May 25, 2015
*/
@TypeDiscriminator("doc.type == 'Error'")
@TypeDiscriminator("doc.type == 'ErrorTrace'")
public class ErrorTrace extends MotechBaseDataObject {

/*
Expand All @@ -36,7 +38,8 @@ public class ErrorTrace extends MotechBaseDataObject {
private String documentType;
@JsonProperty
private String retryUrl;

@JsonProperty
private Map<String, String> details;
// dateoccured , dateclosed , errortype =name, documenttype , submiturl

public ErrorTrace() {
Expand Down Expand Up @@ -110,7 +113,21 @@ public void setRetryUrl(String retryUrl) {
this.retryUrl = retryUrl;
}

public Map<String, String> getDetails() {
return details;
}

public void setDetails(Map<String, String> details) {
this.details = details;
}

public void addDetails(String key, String val) {
if(details == null){
details = new HashMap<>();
}
details.put(key, val);
}

public String getRecordId() {

return recordId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

import org.ektorp.CouchDbConnector;
import org.ektorp.DocumentNotFoundException;
import org.ektorp.support.GenerateView;
import org.ektorp.support.View;
import org.motechproject.dao.MotechBaseRepository;
import org.opensrp.common.AllConstants;
import org.opensrp.domain.Client;
import org.opensrp.domain.ErrorTrace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.mysql.jdbc.StringUtils;

/**
* @author [email protected]
* Created on May 25, 2015
Expand All @@ -27,41 +31,30 @@ protected AllErrorTrace(
super(ErrorTrace.class, db);
}

//@GenerateView
public ErrorTrace findById(String _id) throws DocumentNotFoundException{

/*db.queryView(createQuery("_id").keys(_id)
.includeDocs(true), ErrorTrace.class);*/
ErrorTrace errors= (ErrorTrace)get(_id);
//List<ErrorTrace> errors = queryView("_id", _id);
if (errors == null ) {
System.out.println("Error by id : = found nothing !");
return null;
}
System.out.println("Error by id : = "+errors);
return errors;
return get(_id);
}

public boolean exists(String id) {
return findById(id) != null;
}

@View(name = "all_errors", map = "function(doc) { emit(doc.id); }")
@View(name = "all_errors", map = "function(doc) { if (doc.type === 'ErrorTrace') { emit(doc.id); } }")
public List<ErrorTrace> findAllErrors() throws DocumentNotFoundException{
return db.queryView(createQuery("all_errors").includeDocs(true),
ErrorTrace.class);
}

@View(name = "all_unsolved_errors", map = "function(doc) { if (doc.status === 'unsolved') { emit(doc.id); } }")
public List<ErrorTrace> findAllUnSolvedErrors() throws DocumentNotFoundException {
return db.queryView(createQuery("all_unsolved_errors").includeDocs(true),
ErrorTrace.class);
@View(name = "all_errors_by_status", map = "function(doc) { if (doc.type === 'ErrorTrace') { emit(doc.status); } }")
public List<ErrorTrace> findErrorsByStatus(String status) throws DocumentNotFoundException {
return db.queryView(createQuery("all_errors_by_status").
key(status).includeDocs(true), ErrorTrace.class);
}

@View(name = "all_solved_errors", map = "function(doc) { if (doc.status === 'solved') { emit(doc.id); } }")
/*@View(name = "all_solved_errors", map = "function(doc) { if (doc.status === 'solved') { emit(doc.id); } }")
public List<ErrorTrace> findAllSolvedErrors() throws DocumentNotFoundException {
return db.queryView(createQuery("all_solved__errors").includeDocs(true),
ErrorTrace.class);
}
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class ErrorTraceService {

private final AllErrorTrace allErrorTrace;


@Autowired
public ErrorTraceService(AllErrorTrace allErrorTrace) {
this.allErrorTrace=allErrorTrace;
Expand Down Expand Up @@ -50,63 +49,21 @@ public void log(String errorType , String documentType, String recordId ,String
error.setRetryUrl(retryURL);
error.setDateOccurred(new Date());
addError(error);

}

public void updateError(ErrorTrace entity){
allErrorTrace.update(entity);
}

public List<ErrorTrace> getAllErrors() throws DocumentNotFoundException{


ArrayList<ErrorTrace> allErrorList= (ArrayList<ErrorTrace>) allErrorTrace.findAllErrors();
if(null==allErrorList || allErrorList.isEmpty()){
return null;

}


return allErrorList;

public List<ErrorTrace> getAllError() throws DocumentNotFoundException{
return allErrorTrace.findAllErrors();
}

public List<ErrorTrace> getAllSolvedErrors() throws DocumentNotFoundException{


ArrayList<ErrorTrace> allErrorList= (ArrayList<ErrorTrace>) allErrorTrace.findAllSolvedErrors();
if(null==allErrorList || allErrorList.isEmpty()){
return null;

}


return allErrorList;

public List<ErrorTrace> getErrorsByStatus(String errorStatus) throws DocumentNotFoundException{
return allErrorTrace.findErrorsByStatus(errorStatus);
}

public List<ErrorTrace> getAllUnsolvedErrors() throws DocumentNotFoundException{


ArrayList<ErrorTrace> allErrorList= (ArrayList<ErrorTrace>) allErrorTrace.findAllUnSolvedErrors();
if(null==allErrorList || allErrorList.isEmpty()){
return null;

}


return allErrorList;

}

public ErrorTrace getError(String id) throws DocumentNotFoundException{

return allErrorTrace.findById(id);


return allErrorTrace.findById(id);
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@



import httpdowload.JustForFun;

/*import httpdowload.JustForFun;
*/
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
Expand Down Expand Up @@ -55,7 +55,7 @@ public XlsFormDownloaderService() {

public static void main(String[] args) {
try {
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
/*new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
"maimoonak", "opensrp", JustForFun.Form, "child_vaccination_enrollment", "135187");
//-------------------------
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
Expand All @@ -66,7 +66,7 @@ public static void main(String[] args) {
//----------------------------
new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
"maimoonak", "opensrp", JustForFun.Form, "woman_tt_followup_form", "135203");

*/
/*new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
"maimoonak", "opensrp", JustForFun.Form, "vaccine_stock_position", "115142");

Expand All @@ -77,7 +77,7 @@ public static void main(String[] args) {

new XlsFormDownloaderService().downloadFormFiles("D:\\opensrpVaccinatorWkspc\\forms",
"maimoonak", "opensrp", JustForFun.Form, "offsite_woman_followup_form", "115135");*/
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void main(String[] args) {
System.out.println(new DateTime("2016-01-23").toString("MMMM (yyyy)"));
}

@Test
@Ignore @Test
public void shouldSearchFullDataClientsIn10Sec() throws MalformedURLException {

/*org.ektorp.http.HttpClient httpClient = new StdHttpClient.Builder().url("http://202.141.249.106:6808").build();
Expand Down Expand Up @@ -151,7 +151,7 @@ void addClient(int i, boolean direct, CouchDbConnector db){
int ageInWeeks = new Random().nextInt(2860);// assuming average age of people is 55 years
DateTime birthdate = new DateTime().minusWeeks(ageInWeeks);
DateTime deathdate = i%7==0?new DateTime():null;// every 7th person died today
Client c = new Client("entityId"+i, "firstName"+i, "middleName"+i, "lastName"+i, birthdate, deathdate, false, false, i%2==0?"FEMALE":"MALE");
Client c = new Client("entityId"+i, "firstName"+i, "middleName"+i, "lastName"+i, birthdate, deathdate, false, false, i%2==0?"FEMALE":"MALE","");

Map<String, String> am = new HashMap<>();
Address ab = new Address("birthplace", null, null, am , null, null, null, "Sindh", "Pakistan");
Expand Down Expand Up @@ -183,7 +183,7 @@ else if(direct){
}
}

@Test
@Ignore @Test
public void shouldGetByDynamicView() {
addClients();
List<Client> l2 = clientService.findByCriteria(null, "MALE", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.opensrp.repository.it;

import static org.mockito.MockitoAnnotations.initMocks;
import static org.junit.Assert.*;

import java.util.Date;
import java.util.Random;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -20,24 +22,39 @@ public class AllErrorTraceIntegrationTest {

@Autowired
private AllErrorTrace allErrorTrace;

@Before
public void setUp() throws Exception {
initMocks(this);
allErrorTrace.removeAll();
}

@Test
public void shouldAddError()throws Exception
{
//ErrorTrace error=new ErrorTrace(new Date(), "Error Testing" , "not availalbe","this is an Testing Error", "unsolved");
Random ran=new Random();
try
{
throw new RuntimeException("My Test Msg");
}
catch(Exception e){
for(int i=0;i<15;i++)
{
ErrorTrace error=new ErrorTrace();
error.setErrorType("error loggging test");
error.setDate(new Date());
error.setStackTrace("Complete Stack Trace :");
error.setStatus("unsolved");
error.setDocumentType("Test Document");
// error.setErrorType("test Error");
error.setRecordId(String.valueOf(ran.nextInt(100000)+ran.nextInt(1002)));
allErrorTrace.add(error);

}
assertTrue(allErrorTrace.findErrorsByStatus("unsolved").size() == 15);
assertTrue(allErrorTrace.findErrorsByStatus("solved").size() <15);

}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.lang.StringUtils;
import org.opensrp.form.domain.FormField;
import org.opensrp.form.domain.FormSubmission;
import org.opensrp.form.domain.SubFormData;
Expand All @@ -42,7 +43,6 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.mysql.jdbc.StringUtils;

/**
* The class is the bridge that allows parsing and mapping of formSubmission fields with
Expand Down Expand Up @@ -76,7 +76,7 @@ public FormSubmissionMap createFormSubmissionMap(FormSubmission fs) throws JsonI
Map<String, String> fieldAttributes = bindPath==null?new HashMap<String, String>():getAttributesForBindPath(bindPath, modelXml);

boolean ismultiselect = bindPath==null?false:isMultiselect(bindPath, jsonForm);
if(!StringUtils.isEmptyOrWhitespaceOnly(fsf.value())){
if(!StringUtils.isBlank(fsf.value())){
if(ismultiselect){
String[] vals = fsf.value().split(" ");
Map<String, Map<String, String>> valCods = new HashMap<>();
Expand Down Expand Up @@ -539,7 +539,7 @@ public Map<String, String> getAttributesForSubform (String subformName, FormSubm
public Map<String, String> getInstanceAttributesForFormFieldAndValue(String fieldName, String fieldVal, String subform, String formName, JsonObject formDefinition, JsonObject jsonForm) throws JsonSyntaxException, IOException
{
String bindPath = null;
if(StringUtils.isEmptyOrWhitespaceOnly(subform)){
if(StringUtils.isBlank(subform)){
bindPath = getPropertyBindFromFormDefinition(fieldName, formName, formDefinition);
}
else {
Expand All @@ -552,7 +552,7 @@ public Map<String, String> getInstanceAttributesForFormFieldAndValue(String fiel
public Map<String, String> getInstanceAttributesForFormFieldAndValue(String fieldName, String fieldVal, String subform, FormSubmission fs) throws JsonSyntaxException, IOException
{
String bindPath = null;
if(StringUtils.isEmptyOrWhitespaceOnly(subform)){
if(StringUtils.isBlank(subform)){
bindPath = getPropertyBindFromFormDefinition(fieldName, fs.formName(), getFormDefinitionData(fs.formName()));
}
else {
Expand Down
Loading