Add Enum TableID , and class User
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import ProtegeData.TableID;
|
||||
import ProtegeData.User;
|
||||
import jakarta.xml.bind.JAXBContext;
|
||||
import jakarta.xml.bind.Unmarshaller;
|
||||
import org.datacontract.schemas._2004._07.gxwcf2.Logon;
|
||||
import org.datacontract.schemas._2004._07.gxwcf2.ObjectFactory;
|
||||
import org.pmw.tinylog.Logger;
|
||||
@@ -5,6 +9,13 @@ import org.tempuri.IService1;
|
||||
import org.tempuri.Service1;
|
||||
import jakarta.xml.ws.Holder;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static Logon logon;
|
||||
static ObjectFactory factory = new ObjectFactory();
|
||||
@@ -25,18 +36,68 @@ public class Main {
|
||||
logon.setPassword(factory.createLogonPassword(""));
|
||||
|
||||
GetVersion();
|
||||
GetRecord(502,4,4);
|
||||
GetUsers(4,3,4);
|
||||
|
||||
// LocalDate today = LocalDate.now();
|
||||
// LocalDateTime startofDay = today.atStartOfDay();
|
||||
// LocalDateTime endofDay = today.atTime(23,59,59);
|
||||
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
// RunReport(6,4,0,200, formatter.format(startofDay),formatter.format(endofDay));
|
||||
}
|
||||
|
||||
private static void GetRecord(long TableID, long ParentID, long RecordID){
|
||||
basichttp.getRecord(logon, TableID, ParentID, RecordID, Result, ErrorCode, ErrorMsg, Success);
|
||||
/**
|
||||
* Get Users
|
||||
* Dapat dari tableID 100
|
||||
* @param SiteID SiteID
|
||||
* @param startindex start index of the record
|
||||
* @param endindex end index of the record
|
||||
*/
|
||||
private static List<User> GetUsers(long SiteID, long startindex, long endindex){
|
||||
List<User> users = new ArrayList<>();
|
||||
try{
|
||||
JAXBContext context = JAXBContext.newInstance(User.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
for(long i = startindex; i <= endindex; i++){
|
||||
if (GetRecord(TableID.Users, SiteID, i)){
|
||||
User _user = (User) unmarshaller.unmarshal(new StringReader(Result.value));
|
||||
Logger.info("User [{}]: {}" , i, _user.toString());
|
||||
Logger.info("User [{}]: {}" , i,Result.value);
|
||||
}
|
||||
}
|
||||
} catch (Exception e){
|
||||
Logger.error("Error: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
private static void RunReport(long nID, long siteID, long startRow, long numberOfRows, String startDate, String endDate){
|
||||
if (startDate==null) startDate = "";
|
||||
if (endDate==null) endDate = "";
|
||||
int reportType = 4;
|
||||
long tableID = 0;
|
||||
long controllerID = -1;
|
||||
int langID = 0;
|
||||
long recordGroup = 0;
|
||||
int deviceReportDetail = 0;
|
||||
basichttp.runReport(logon, reportType,tableID, nID,siteID,controllerID,startRow,numberOfRows,langID,recordGroup, startDate, !startDate.isEmpty(), endDate, !endDate.isEmpty(), Result, ErrorCode, ErrorMsg, deviceReportDetail, Success);
|
||||
if (Success.value) {
|
||||
Logger.info("Record: {}" , Result.value);
|
||||
Logger.info("Report: {}" , Result.value);
|
||||
} else {
|
||||
Logger.error("Error Code: {}, Message: {}" ,ErrorCode.value, ErrorMsg.value);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean GetRecord(TableID id, long ParentID, long RecordID){
|
||||
basichttp.getRecord(logon, id.Value, ParentID, RecordID, Result, ErrorCode, ErrorMsg, Success);
|
||||
// if (Success.value) {
|
||||
// Logger.info("Record: {}" , Result.value);
|
||||
// } else {
|
||||
// Logger.error("Error Code: {}, Message: {}" ,ErrorCode.value, ErrorMsg.value);
|
||||
// }
|
||||
return Success.value;
|
||||
}
|
||||
|
||||
private static void GetVersion(){
|
||||
basichttp.getVersion(logon, Result, ErrorCode, ErrorMsg, Success);
|
||||
if (Success.value) {
|
||||
|
||||
9
src/ProtegeData/TableID.java
Normal file
9
src/ProtegeData/TableID.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package ProtegeData;
|
||||
|
||||
public enum TableID {
|
||||
Users(100);
|
||||
public long Value;
|
||||
TableID(long value){
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
49
src/ProtegeData/User.java
Normal file
49
src/ProtegeData/User.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package ProtegeData;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
||||
/**
|
||||
* Class User for used in TableID 100
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@XmlRootElement(name="UsersData")
|
||||
public class User {
|
||||
|
||||
@XmlElement(name="UserCardNumberGroupData")
|
||||
public UserCardNumberGroupData UserCardNumber;
|
||||
|
||||
@XmlElement(name="FirstName")
|
||||
public String FirstName;
|
||||
|
||||
@XmlElement(name="LastName")
|
||||
public String LastName;
|
||||
|
||||
@XmlElement(name="Name")
|
||||
public String Name;
|
||||
|
||||
@XmlElement(name="Name2")
|
||||
public String Name2;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "CardNumber: " + UserCardNumber.data.CardNumber + ", LastUsed: " + UserCardNumber.data.LastUsed + ", LastUsedValid: "+ UserCardNumber.data.LastUsedValid+ ", FirstName: " + FirstName + ", LastName: " + LastName;
|
||||
}
|
||||
|
||||
static class UserCardNumberGroupData{
|
||||
@XmlElement(name="UserCardNumberGroupDataData")
|
||||
public UserCardNumberGroupDataData data;
|
||||
}
|
||||
|
||||
static class UserCardNumberGroupDataData{
|
||||
@XmlElement(name="CardLastUsed")
|
||||
public String LastUsed;
|
||||
|
||||
@XmlElement(name="CardLastUsedValid")
|
||||
public boolean LastUsedValid;
|
||||
|
||||
@XmlElement(name="CardNumber")
|
||||
public String CardNumber;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user