|
@@ -5,9 +5,11 @@ import { ConvertedResult } from "../entities/ConvertedResult";
|
|
|
import { DataServiceMessage } from "../entities/DataService.entity";
|
|
|
import { SummaryResponse } from "../entities/DescendentDataServiceArgument.entity";
|
|
|
import { StatusResponse } from "../entities/StatusResponse";
|
|
|
-import { FisCreateMessageUtility, Query, DataTypeProfile, MessageTypeProfile, ResponseMessage,
|
|
|
- FisReadDataUtility, GenericFisData,
|
|
|
- GenericFisRowColumn } from "../message/fisappmessagejsutility/interface/export";
|
|
|
+import {
|
|
|
+ FisCreateMessageUtility, Query, DataTypeProfile, MessageTypeProfile, ResponseMessage,
|
|
|
+ FisReadDataUtility, GenericFisData,
|
|
|
+ GenericFisRowColumn
|
|
|
+} from "../message/fisappmessagejsutility/interface/export";
|
|
|
|
|
|
import { State } from "./state";
|
|
|
|
|
@@ -15,7 +17,7 @@ export class CommonDataService {
|
|
|
|
|
|
public tempData: any;
|
|
|
// static ResponseService: FisUASRequestMessage;
|
|
|
- static ResponseService:FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
|
|
|
+ static ResponseService: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
|
|
|
public ucpId: string;
|
|
|
public CurrentState: string = State.Initialisation.Code
|
|
|
|
|
@@ -34,24 +36,24 @@ export class CommonDataService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- getDataFromServer(http: HttpService, ucpId: string, data):Observable<any>{
|
|
|
+ getDataFromServer(http: HttpService, ucpId: string, data): Observable<any> {
|
|
|
return this.httpRequest(http, ucpId, data)
|
|
|
}
|
|
|
|
|
|
- getData(className, filter, returnFormatType):any {
|
|
|
+ getData(className, filter, returnFormatType): any {
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
- return new Observable(subscriber=>{
|
|
|
+ return new Observable(subscriber => {
|
|
|
|
|
|
let message: string;
|
|
|
let result: [] | string;
|
|
|
// try {
|
|
|
|
|
|
- this.getDataWithStatus(className,filter, returnFormatType, 1).subscribe({
|
|
|
+ this.getDataWithStatus(className, filter, returnFormatType, 1).subscribe({
|
|
|
next: (res) => {
|
|
|
result = res;
|
|
|
subscriber.next(result)
|
|
|
},
|
|
|
- error: (e)=>{
|
|
|
+ error: (e) => {
|
|
|
subscriber.error(e)
|
|
|
}
|
|
|
|
|
@@ -59,80 +61,78 @@ export class CommonDataService {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
- getDataWithType(filter, className:string, message:any, returnFormatType:string, data:any[]): any {
|
|
|
|
|
|
+ getDataWithType(filter, className: string, message: any, returnFormatType: string, data: any[]): any {
|
|
|
|
|
|
- return new Observable((subscriber)=>{
|
|
|
|
|
|
- let key = []
|
|
|
- let value = []
|
|
|
- if (filter) { //check whether filter existed
|
|
|
- let semicolumn = filter.split(";"); //separate the semicolumn
|
|
|
- for (let i = 0; i < semicolumn.length; i++) {
|
|
|
- key[i] = semicolumn[i].split("=")[0];
|
|
|
- value[i] = semicolumn[i].split("=")[1];
|
|
|
- }
|
|
|
+ return new Observable((subscriber) => {
|
|
|
+
|
|
|
+ let key = []
|
|
|
+ let value = []
|
|
|
+ if (filter) { //check whether filter existed
|
|
|
+ let semicolumn = filter.split(";"); //separate the semicolumn
|
|
|
+ for (let i = 0; i < semicolumn.length; i++) {
|
|
|
+ key[i] = semicolumn[i].split("=")[0];
|
|
|
+ value[i] = semicolumn[i].split("=")[1];
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- this.getDataFromServer(this.http, this.ucpId, this.currentData).subscribe({
|
|
|
+ this.getDataFromServer(this.http, this.ucpId, this.currentData).subscribe({
|
|
|
// .then((res: ResponseMessage)=> {
|
|
|
- next: (res: ResponseMessage)=>{
|
|
|
- const dataUtil:FisReadDataUtility = new FisReadDataUtility();
|
|
|
+ next: (res: ResponseMessage) => {
|
|
|
+ const dataUtil: FisReadDataUtility = new FisReadDataUtility();
|
|
|
const messageType: MessageTypeProfile = new MessageTypeProfile();
|
|
|
- const dataType:DataTypeProfile = new DataTypeProfile();
|
|
|
+ const dataType: DataTypeProfile = new DataTypeProfile();
|
|
|
|
|
|
|
|
|
// const readData = dataUtil.readDataType(res, referenceType);
|
|
|
- let genericFisData:GenericFisData;
|
|
|
- let result:GenericFisRowColumn[];
|
|
|
+ let genericFisData: GenericFisData;
|
|
|
+ let result: GenericFisRowColumn[];
|
|
|
|
|
|
- let readData:any;
|
|
|
+ let readData: any;
|
|
|
|
|
|
- if(res.data[0].data && res.data[0].data['GenericFisData'])
|
|
|
- {
|
|
|
- readData = dataUtil.readDataType(res.data[0].header.requestMessageRespondTo, res.data[0], messageType,dataType)
|
|
|
- }else{
|
|
|
+ if (res.data[0].data && res.data[0].data['GenericFisData']) {
|
|
|
+ readData = dataUtil.readDataType(res.data[0].header.requestMessageRespondTo, res.data[0], messageType, dataType)
|
|
|
+ } else {
|
|
|
dataType.name = "GenericFisData";
|
|
|
readData = res;
|
|
|
}
|
|
|
|
|
|
|
|
|
- if(dataType.name == "GenericFisData"){
|
|
|
+ if (dataType.name == "GenericFisData") {
|
|
|
genericFisData = readData as GenericFisData;
|
|
|
-
|
|
|
result = genericFisData.data[this.dataName].rows.row.filter(val => {
|
|
|
|
|
|
- if (filter) {
|
|
|
- for (let i = 0; i < key.length; i++) {
|
|
|
- if (val.column[key[i]] != value[i]) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ if (filter) {
|
|
|
+ for (let i = 0; i < key.length; i++) {
|
|
|
+ if (val.column[key[i]] != value[i]) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- return true
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return true
|
|
|
+
|
|
|
+ }).map(x => x.column);
|
|
|
|
|
|
- }).map(x => x.column);
|
|
|
-
|
|
|
|
|
|
data = this.chunkFormatType(returnFormatType, result, 0);
|
|
|
-
|
|
|
- let returnMessage:DataServiceMessage[] = message;
|
|
|
|
|
|
- let summaryMessage:SummaryResponse = new SummaryResponse();
|
|
|
+ let returnMessage: DataServiceMessage[] = message;
|
|
|
+
|
|
|
+ let summaryMessage: SummaryResponse = new SummaryResponse();
|
|
|
|
|
|
- summaryMessage.className = className;
|
|
|
- summaryMessage.filter = filter;
|
|
|
- summaryMessage.returnFormatType = returnFormatType;
|
|
|
- summaryMessage.returnSequenceTotal = result.length;
|
|
|
+ summaryMessage.className = className;
|
|
|
+ summaryMessage.filter = filter;
|
|
|
+ summaryMessage.returnFormatType = returnFormatType;
|
|
|
+ summaryMessage.returnSequenceTotal = result.length;
|
|
|
|
|
|
let statusResponse = new StatusResponse();
|
|
|
statusResponse.status = "1";
|
|
|
|
|
|
|
|
|
- let dataReturn:APAccountProfile[] = data;
|
|
|
+ let dataReturn: APAccountProfile[] = data;
|
|
|
|
|
|
message = [
|
|
|
summaryMessage,
|
|
@@ -140,13 +140,13 @@ export class CommonDataService {
|
|
|
statusResponse,
|
|
|
];
|
|
|
|
|
|
- let messageName = className.replace('DataService','') + "Message";
|
|
|
+ let messageName = className.replace('DataService', '') + "Message";
|
|
|
|
|
|
subscriber.next({
|
|
|
StatusResponse: statusResponse,
|
|
|
SummaryResponse: summaryMessage,
|
|
|
[messageName]: {
|
|
|
- data:dataReturn
|
|
|
+ data: dataReturn
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -154,10 +154,10 @@ export class CommonDataService {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
+ })
|
|
|
|
|
|
|
|
|
- })
|
|
|
+ })
|
|
|
|
|
|
|
|
|
}
|
|
@@ -167,7 +167,7 @@ export class CommonDataService {
|
|
|
returnFormatType: string,
|
|
|
gq, chunkSize = null): Observable<any> {
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
- return new Observable((subscriber)=>{
|
|
|
+ return new Observable((subscriber) => {
|
|
|
|
|
|
let JSONstring: string;
|
|
|
let convertedResult: DataServiceMessage;
|
|
@@ -176,30 +176,30 @@ export class CommonDataService {
|
|
|
let result = [];
|
|
|
// try {
|
|
|
|
|
|
- if (this.CurrentState = State.Initialisation.Code) {
|
|
|
-
|
|
|
- JSONstring = State.Initialisation.Message
|
|
|
+ if (this.CurrentState = State.Initialisation.Code) {
|
|
|
|
|
|
- }
|
|
|
+ JSONstring = State.Initialisation.Message
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.CurrentState = State.Busy.Code) {
|
|
|
|
|
|
- if (this.CurrentState = State.Busy.Code) {
|
|
|
-
|
|
|
-
|
|
|
- JSONstring = State.Busy.Message
|
|
|
- }
|
|
|
|
|
|
- if (this.CurrentState = State.Ready.Code) {
|
|
|
+ JSONstring = State.Busy.Message
|
|
|
+ }
|
|
|
|
|
|
- // Retrieve new data from server
|
|
|
- this.getDataFromServer(this.http, this.ucpId, this.currentData).subscribe({
|
|
|
- next: (res)=>{
|
|
|
-
|
|
|
- // .then(res => {
|
|
|
+ if (this.CurrentState = State.Ready.Code) {
|
|
|
+
|
|
|
+ // Retrieve new data from server
|
|
|
+ this.getDataFromServer(this.http, this.ucpId, this.currentData).subscribe({
|
|
|
+ next: (res) => {
|
|
|
+
|
|
|
+ // .then(res => {
|
|
|
if (res == null) // Check if it is null
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
JSONstring = State.Error.Message + "No data entity in cache to filter"
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
else {
|
|
|
|
|
@@ -207,8 +207,8 @@ export class CommonDataService {
|
|
|
res['data'].DataService === undefined ||
|
|
|
res['data'].DataService.rows['row'] === undefined
|
|
|
) { //check whether row entity exist before perform filter
|
|
|
-
|
|
|
- JSONstring = State.Error.Message + " No row entity in filter"
|
|
|
+
|
|
|
+ JSONstring = State.Error.Message + " No row entity in filter"
|
|
|
} else {
|
|
|
|
|
|
let key = []
|
|
@@ -226,7 +226,7 @@ export class CommonDataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (res['data'].DataService.rows.row.length > 0) // check whether got any record returned
|
|
|
+ if (res['data'].DataService.rows.row.length > 0) // check whether got any record returned
|
|
|
{
|
|
|
|
|
|
|
|
@@ -276,16 +276,16 @@ export class CommonDataService {
|
|
|
} else { //result return to subscriberProxy
|
|
|
|
|
|
// result.map((el, idx) => { //will be use to subscribe multiple observable from back office
|
|
|
- convertedResult = new ConvertedResult(
|
|
|
- className,
|
|
|
- result[0],
|
|
|
- filter,
|
|
|
- returnFormatType,
|
|
|
- result.length,
|
|
|
- result.length + 1
|
|
|
- );
|
|
|
-
|
|
|
- // res.push(convertedResult)
|
|
|
+ convertedResult = new ConvertedResult(
|
|
|
+ className,
|
|
|
+ result[0],
|
|
|
+ filter,
|
|
|
+ returnFormatType,
|
|
|
+ result.length,
|
|
|
+ result.length + 1
|
|
|
+ );
|
|
|
+
|
|
|
+ // res.push(convertedResult)
|
|
|
// })
|
|
|
subscriber.next(convertedResult)
|
|
|
}
|
|
@@ -316,22 +316,22 @@ export class CommonDataService {
|
|
|
);
|
|
|
|
|
|
subscriber.next(JSONstring);
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
// } catch (e) {
|
|
|
- subscriber.error(e=>{
|
|
|
+ subscriber.error(e => {
|
|
|
|
|
|
- return convertedResult = new ConvertedResult(
|
|
|
- className,
|
|
|
- State.Error.Message + e.Message,
|
|
|
- filter,
|
|
|
- returnFormatType
|
|
|
- );
|
|
|
+ return convertedResult = new ConvertedResult(
|
|
|
+ className,
|
|
|
+ State.Error.Message + e.Message,
|
|
|
+ filter,
|
|
|
+ returnFormatType
|
|
|
+ );
|
|
|
|
|
|
- })
|
|
|
+ })
|
|
|
|
|
|
- // reject(convertedResult);
|
|
|
+ // reject(convertedResult);
|
|
|
// }
|
|
|
|
|
|
})
|
|
@@ -340,15 +340,15 @@ export class CommonDataService {
|
|
|
|
|
|
|
|
|
|
|
|
- public httpRequest(http, ucpId, data: string):Observable<any> {
|
|
|
+ public httpRequest(http, ucpId, data: string): Observable<any> {
|
|
|
if (!CommonDataService.ResponseService) {
|
|
|
CommonDataService.ResponseService = new FisCreateMessageUtility('getQueryMessage');
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
- return http.post(process.env.UCP_HOST, CommonDataService.ResponseService.getQueryMessage(ucpId,Query.GetData, data))
|
|
|
-
|
|
|
+ return http.post(process.env.UCP_HOST, CommonDataService.ResponseService.getQueryMessage(ucpId, Query.GetData, data))
|
|
|
+
|
|
|
} catch (e) {
|
|
|
console.log(e)
|
|
|
throw e;
|
|
@@ -372,7 +372,7 @@ export class CommonDataService {
|
|
|
} else if (chunkSize > 1) { // record by batch of #
|
|
|
let result = this.chunk(data, chunkSize);
|
|
|
|
|
|
- return block != null ? result[block]: result;
|
|
|
+ return block != null ? result[block] : result;
|
|
|
} else { //record return by FULL
|
|
|
return data;
|
|
|
}
|
|
@@ -390,8 +390,7 @@ export class CommonDataService {
|
|
|
return chunks;
|
|
|
}
|
|
|
|
|
|
- public validate(key,value):string
|
|
|
- {
|
|
|
+ public validate(key, value): string {
|
|
|
return "";
|
|
|
}
|
|
|
}
|