Commit bec22aed authored by support-modus's avatar support-modus

Ενημέρωση client

Ενημέρωση client
parent 44076dad
......@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gr.mimedu.protocol</groupId>
<artifactId>mineduclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0</version>
<name>mineduclient</name>
<description>Client βιβλιοθήκη για το πρωτόκολλο του υπουργείου παιδείας</description>
<properties>
......@@ -50,5 +50,41 @@
<version>1.3.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>thirdparty</id>
<url>http://desvsrv:8081/nexus/content/repositories/thirdparty</url>
</repository>
<repository>
<id>snapshots</id>
<url>http://desvsrv:8081/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>releases</id>
<url>http://desvsrv:8081/nexus/content/repositories/releases</url>
</repository>
<repository>
<id>elasticsearch-releases</id>
<url>http://maven.elasticsearch.org/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>deployment</id>
<name>Internal Releases</name>
<url>http://devsrv:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>deployment</id>
<name>Internal Releases</name>
<url>http://devsrv:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
\ No newline at end of file
......@@ -14,12 +14,14 @@ import javax.ws.rs.core.Response;
import com.google.gson.Gson;
import gr.mimedu.papyros.protocol.exceptions.AuthenticateException;
import gr.mimedu.papyros.protocol.exceptions.DocumentException;
import gr.mimedu.papyros.protocol.exceptions.SearchException;
import gr.mimedu.papyros.protocol.utils.GsonUtils;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.Document;
import gr.minedu.papyros.protocol.dto.DocumentDataDto;
import gr.minedu.papyros.protocol.dto.DocumentDto;
import gr.minedu.papyros.protocol.dto.ErrorReport;
import gr.minedu.papyros.protocol.dto.Search;
import gr.mineedu.papyros.protocol.idto.Config;
......@@ -30,10 +32,10 @@ public class DocumentClient {
private static final Logger logger = Logger.getLogger(Search.class.getName());
public Document getPdf(String docHashId,ApiKey apikey) throws SearchException, AuthenticateException {
public DocumentDto getPdf(String docHashId,ApiKey apikey) throws DocumentException, AuthenticateException {
if(apikey==null){throw new AuthenticateException(0,"Api key is null");}
Document output = new Document();
DocumentDto output = new DocumentDto();
Client client = ClientBuilder.newClient();
String targetHost=conf.getServerurl();
String path = OpenPapyrosServices.GetDocumentPdf.getValue()+"/"+docHashId;
......@@ -47,11 +49,11 @@ public class DocumentClient {
logger.finest(responseStr);
if(response.getStatus()==Response.Status.OK.getStatusCode()){
output = new Gson().fromJson(responseStr,Document.class) ;
output = new Gson().fromJson(responseStr,DocumentDto.class) ;
}
else{
ErrorReport errorReport = new Gson().fromJson(responseStr,ErrorReport.class) ;
throw new SearchException(errorReport.getErrorCode(),errorReport.getErrorMessage());
throw new DocumentException(errorReport.getErrorCode(),errorReport.getErrorMessage());
}
return output;
}
......
package gr.mimedu.papyros.protocol.exceptions;
public class DocumentException extends Exception{
int code;
String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public DocumentException(){
super();
}
public DocumentException(String msg){
super(msg);
}
public DocumentException(Integer code, String msg){
super(msg);
this.code=code;
}
}
\ No newline at end of file
package gr.minedu.papyros.protocol.dto;
public class Document {
private String base64;
public Document(){
}
public Document(String base64){
this.base64= base64;
}
public String getBase64() {
return base64;
......
......@@ -11,11 +11,19 @@ package gr.minedu.papyros.protocol.dto;
*/
public class DocumentDto {
private String document;
private Document document;
private String fileName;
private String description;
public String getDescription() {
public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
public String getDescription() {
return description;
}
......@@ -31,12 +39,5 @@ public class DocumentDto {
this.fileName = fileName;
}
public String getDocument() {
return document;
}
public void setDocument(String document) {
this.document = document;
}
}
......@@ -18,7 +18,16 @@ public class ProtocolNumber {
public String docId;
public int protocolYear;
public String protocolNumber;
public String protocolDate;
public String getProtocolDate() {
return protocolDate;
}
public void setProtocolDate(String protocolDate) {
this.protocolDate = protocolDate;
}
public String protocolNumber;
public List<DocumentInfo> attachments = new ArrayList<DocumentInfo>();
......
package clientTests;
import java.util.logging.Logger;
import org.junit.Test;
import com.google.gson.Gson;
import gr.mimedu.papyros.protocol.DocumentClient;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.mimedu.papyros.protocol.utils.GsonUtils;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.DocumentDataDto;
public class DocumentDataNoReturnTest {
private static final Logger log = Logger.getLogger(DocumentDataNoReturnTest.class.getName());
@Test
public void getDocumentDataNoData() throws Exception {
log.info("getDocumentDataNoData test");
DocumentClient obj = new DocumentClient();
String docHashId = "sss";
ApiKey apikey =null;
try {
PAuthClient pauth = new PAuthClient();
apikey = pauth.auth("string", "string");
log.info("Apikey:"+new Gson().toJson(apikey));
DocumentDataDto docData = obj.getDocumentData(docHashId, apikey) ;
log.info("docData:"+new Gson().toJson(docData));
} catch (Exception e) {
log.severe(e.getMessage());
}
}
@Test
public void getProtocolGetData() throws Exception {
Gson gson= GsonUtils.build();
log.info("getDocumentData test");
DocumentClient obj = new DocumentClient();
String docHashId = "1dwmF7ycRPo2aO7dlPxLcg==";
ApiKey apikey =null;
try {
PAuthClient pauth = new PAuthClient();
apikey = pauth.auth("anagnosg", "123456");
log.info("Apikey:"+new Gson().toJson(apikey));
DocumentDataDto docData = obj.getDocumentData(docHashId, apikey) ;
//Gson gson= new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssX").create();
log.info("docData:"+gson.toJson(docData));
} catch (Exception e) {
log.severe(e.getMessage());
}
}
}
package clientTests;
import java.util.logging.Logger;
import org.junit.Test;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import clientTests.utils.ProtocolBuilder;
import gr.mimedu.papyros.protocol.DocumentClient;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.mimedu.papyros.protocol.ProtocolSubmitClient;
import gr.mimedu.papyros.protocol.utils.GsonUtils;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.DocumentDataDto;
import gr.minedu.papyros.protocol.dto.ProtocolNumber;
import gr.minedu.papyros.protocol.dto.Protocolin;
public class DocumentDataTest {
private static final Logger log = Logger.getLogger(DocumentDataTest.class.getName());
/**
*
* @throws Exception
*/
@Test
public void protocolGetData() throws Exception {
Gson gson= GsonUtils.build();
log.info("protocolGetData test");
DocumentClient obj = new DocumentClient();
ApiKey apikey =null;
try {
PAuthClient pauth = new PAuthClient();
apikey = pauth.auth("anagnosg", "123456");
log.info("Apikey:"+gson.toJson(apikey));
Protocolin prot = ProtocolBuilder.build();
ProtocolSubmitClient protClient = new ProtocolSubmitClient();
ProtocolNumber protocoled = protClient.submitProtocol(prot, apikey);
log.info("protocoled:"+gson.toJson(protocoled));
DocumentDataDto docData = obj.getDocumentData(protocoled.getDocId(), apikey) ;
log.info("docData:"+gson.toJson(docData));
} catch (Exception e) {
e.printStackTrace();
log.severe(e.getMessage());
}
}
}
package clientTests;
import java.io.File;
import java.util.Date;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.glassfish.jersey.internal.util.Base64;
import org.junit.Test;
import com.google.gson.Gson;
import gr.mimedu.papyros.protocol.DocumentClient;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.DocumentDto;
public class DocumentNoReturnTest {
private static final Logger log = Logger.getLogger(DocumentNoReturnTest.class.getName());
@Test
public void getPdfNoData() throws Exception {
log.info("getPdfNoData test");
DocumentClient obj = new DocumentClient();
String docHashId = "sss";
ApiKey apikey = null;
try {
PAuthClient pauth = new PAuthClient();
apikey = pauth.auth("anagnosg", "123456");
log.info("Apikey:" + new Gson().toJson(apikey));
DocumentDto doc = obj.getPdf(docHashId, apikey);
FileUtils.writeByteArrayToFile(new File("c:/test/" + new Date().getTime()+doc.getFileName() + ".pdf"), Base64.decode(doc.getDocument(). getBase64().getBytes()));;
} catch (Exception e) {
log.severe(e.getMessage());
}
}
}
package clientTests;
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.glassfish.jersey.internal.util.Base64;
import org.junit.Test;
import com.google.gson.Gson;
import clientTests.utils.SearchBuilder;
import gr.mimedu.papyros.protocol.DocumentClient;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.mimedu.papyros.protocol.SearchClient;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.Document;
import gr.minedu.papyros.protocol.dto.DocumentDto;
import gr.minedu.papyros.protocol.dto.Search;
public class DocumentTest {
private static final Logger log = Logger.getLogger(DocumentTest.class.getName());
@Test
public void getPdfData() throws Exception {
log.info("getPdfData test");
DocumentClient obj = new DocumentClient();
ApiKey apikey = null;
try {
PAuthClient pauth = new PAuthClient();
apikey = pauth.auth("anagnosg", "123456");
log.info("Apikey:" + new Gson().toJson(apikey));
Search searchCriteria = SearchBuilder.buildSender();
SearchClient search = new SearchClient();
List<String> docHashIds = search.search(searchCriteria, apikey);
log.info(new Gson().toJson(docHashIds));
for(int i = 0 ; i < docHashIds .size() ;i++){
String docHashId = docHashIds.get(i);
DocumentDto doc = obj.getPdf(docHashId, apikey);
log.info(new Gson().toJson(doc));
if(doc!=null){
FileUtils.writeByteArrayToFile(new File("c:/test/" + new Date().getTime()+doc.getFileName() + ".pdf"), Base64.decode(doc.getDocument(). getBase64().getBytes()));
}
else{
log.info("Doc is null docHashId:"+docHashId);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package clientTests;
import java.util.logging.Logger;
import org.junit.Test;
import com.google.gson.Gson;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.mimedu.papyros.protocol.exceptions.AuthenticateException;
import gr.minedu.papyros.protocol.dto.ApiKey;
public class PAuthTest {
private static final Logger log = Logger.getLogger(PAuthTest.class.getName());
@Test
public void pauthWrongUser() throws Exception {
log.info("pauthWrongUser test");
PAuthClient pauth = new PAuthClient();
try {
pauth.auth("test", "test2");
} catch (AuthenticateException e) {
log.severe(e.getMessage());
}
}
@Test
public void pauthWrongPassword() throws Exception {
log.info("pauthWrongPass test");
PAuthClient pauth = new PAuthClient();
try {
pauth.auth("testUsername", "test2");
} catch (AuthenticateException e) {
log.severe(e.getMessage());
}
}
@Test
public void pauthCorrect() throws Exception {
log.info("pauthCorrect test");
PAuthClient pauth = new PAuthClient();
try {
ApiKey apikey = pauth.auth("anagnosg", "123456");
log.info("Apikey:"+new Gson().toJson(apikey));
} catch (AuthenticateException e) {
log.severe(e.getMessage());
e.printStackTrace();
}
}
}
package clientTests;
import java.util.Arrays;
import java.util.logging.Logger;
import org.junit.Test;
import com.google.gson.Gson;
import clientTests.utils.DocumentDtoBuilder;
import clientTests.utils.ProtocolBuilder;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.mimedu.papyros.protocol.ProtocolSubmitClient;
import gr.mimedu.papyros.protocol.exceptions.AuthenticateException;
import gr.mimedu.papyros.protocol.utils.GsonUtils;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.DocCategory;
import gr.minedu.papyros.protocol.dto.DocumentDto;
import gr.minedu.papyros.protocol.dto.ProtocolNumber;
import gr.minedu.papyros.protocol.dto.Protocolin;
public class ProtocolSubmitClientTest {
private static final Logger log = Logger.getLogger(PAuthTest.class.getName());
@Test
public void submitProtocol() throws Exception {
log.info("submitProtocol");
PAuthClient pauth = new PAuthClient();
try {
Protocolin prot = ProtocolBuilder.build();
log.info("prot:"+new Gson().toJson(prot));
ApiKey apiKey = pauth.auth("anagnosg", "123456");
ProtocolSubmitClient protClient = new ProtocolSubmitClient();
ProtocolNumber protocoled = protClient.submitProtocol(prot, apiKey);
log.info("protocoled:"+GsonUtils.build().toJson(protocoled));
} catch (AuthenticateException e) {
log.severe(e.getMessage());
}
}
}
package clientTests;
import java.util.List;
import java.util.logging.Logger;
import org.junit.Test;
import com.google.gson.Gson;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.mimedu.papyros.protocol.SearchClient;
import gr.mimedu.papyros.protocol.exceptions.AuthenticateException;
import gr.mimedu.papyros.protocol.exceptions.SearchException;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.Search;
public class SearchNoReturnTest {
private static final Logger log = Logger.getLogger(SearchTest.class.getName());
@Test
public void searchNoCriteriaData() throws Exception {
log.info("searchNoData");
ApiKey apikey = null;
try {
PAuthClient pauth = new PAuthClient();
apikey = pauth.auth("anagnosg", "123456");
log.info("Apikey:" + new Gson().toJson(apikey));
SearchClient search = new SearchClient();
Search s = new Search();
List<String> docHashIds = search.search(s, apikey);
if (docHashIds != null && docHashIds.size() == 0) {
log.info("docIds size is 0");
}
else{
log.info("size:"+docHashIds.size());
//log.info(new Gson().toJson(docHashIds));
}
} catch (SearchException e) {
log.severe(e.getMessage());
} catch (AuthenticateException e) {
log.severe(e.getMessage());
e.printStackTrace();
}
}
}
package clientTests;
import java.util.List;
import java.util.logging.Logger;
import org.junit.Test;
import com.google.gson.Gson;
import clientTests.utils.SearchBuilder;
import gr.mimedu.papyros.protocol.PAuthClient;
import gr.mimedu.papyros.protocol.SearchClient;
import gr.mimedu.papyros.protocol.exceptions.AuthenticateException;
import gr.mimedu.papyros.protocol.exceptions.SearchException;
import gr.minedu.papyros.protocol.dto.ApiKey;
import gr.minedu.papyros.protocol.dto.Search;
public class SearchTest {
private static final Logger log = Logger.getLogger(SearchTest.class.getName());
@Test
public void searchBySenderIdData() throws Exception {
log.info("searchData");
ApiKey apikey = null;
try {
PAuthClient pauth = new PAuthClient();
apikey = pauth.auth("anagnosg", "123456");
log.info("Apikey:" + new Gson().toJson(apikey));
SearchClient search = new SearchClient();
Search s = SearchBuilder.buildDocTypeSender();
List<String> docHashIds = search.search(s, apikey);
if (docHashIds != null && docHashIds.size() == 0) {
log.info("docIds size is 0");
} else {
for (int i = 0; i < docHashIds.size(); i++) {
log.info((i + 1) + ")docHashId:" + docHashIds.get(i));
}
}
} catch (SearchException e) {
e.printStackTrace();
log.severe(e.getMessage());
} catch (AuthenticateException e) {
log.severe(e.getMessage());
e.printStackTrace();
}
}
}
package clientTests.utils;
import java.util.Base64;
import gr.minedu.papyros.protocol.dto.Document;
import gr.minedu.papyros.protocol.dto.DocumentDto;
public class DocumentDtoBuilder {
public static DocumentDto build(){