|
/*
|
|
* This program is a part of the IoTa Project.
|
|
*
|
|
* Copyright © 2008-2012 Université de Caen Basse-Normandie, GREYC
|
|
* Copyright © 2008-2012 Orange Labs
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
* <http://www.gnu.org/licenses/>
|
|
*
|
|
* See AUTHORS for a list of contributors.
|
|
*/
|
|
package fr.unicaen.iota.discovery.client.gui;
|
|
|
|
import fr.unicaen.iota.discovery.client.DsClient;
|
|
import fr.unicaen.iota.discovery.client.model.Event;
|
|
import fr.unicaen.iota.discovery.client.util.Configuration;
|
|
import fr.unicaen.iota.discovery.client.util.EnhancedProtocolException;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.rmi.RemoteException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Vector;
|
|
import javax.swing.*;
|
|
import javax.swing.table.DefaultTableModel;
|
|
import org.apache.axis2.databinding.types.URI.MalformedURIException;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class QueryClient extends GuiClient {
|
|
|
|
/**
|
|
* Creates new form QueryClient
|
|
*/
|
|
public QueryClient() {
|
|
initComponents();
|
|
initSelfComponent();
|
|
}
|
|
|
|
/**
|
|
* This method is called from within the constructor to initialize the form.
|
|
* WARNING: Do NOT modify this code. The content of this method is always
|
|
* regenerated by the Form Editor.
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
private void initComponents() {
|
|
|
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
|
|
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
|
getContentPane().setLayout(layout);
|
|
layout.setHorizontalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGap(0, 400, Short.MAX_VALUE)
|
|
);
|
|
layout.setVerticalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGap(0, 300, Short.MAX_VALUE)
|
|
);
|
|
|
|
pack();
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
/**
|
|
* @param args the command line arguments
|
|
*/
|
|
public static void main(String args[]) {
|
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
public void run() {
|
|
new QueryClient().setVisible(true);
|
|
}
|
|
});
|
|
}
|
|
private final String DEFAULT_SERVICE_ADDRESS = "http://ds.iota.greyc.fr:8080/ds-unicaen/services/ESDS_Service";
|
|
private JTextField searchForm;
|
|
private JButton searchButton;
|
|
private JTable jTable;
|
|
private Vector<Vector<String>> data;
|
|
private JTextField serviceAddress;
|
|
private JButton testButton;
|
|
|
|
private void initSelfComponent() {
|
|
this.setTitle("DS Query Client");
|
|
this.setSize(800, 400);
|
|
this.setLocationRelativeTo(null);
|
|
this.getContentPane().setLayout(new BorderLayout());
|
|
JPanel j1 = new JPanel();
|
|
j1.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
|
|
this.getContentPane().add(j1, BorderLayout.CENTER);
|
|
j1.setLayout(new BorderLayout());
|
|
JPanel j2 = new JPanel();
|
|
j2.setLayout(new BorderLayout());
|
|
JLabel searchLabel = new JLabel("Search value:");
|
|
searchForm = new JTextField("urn:epc:id:sgtin:1.2.3");
|
|
j2.add(searchForm, BorderLayout.CENTER);
|
|
j2.add(searchLabel, BorderLayout.WEST);
|
|
searchButton = new JButton("search...");
|
|
searchButton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent ae) {
|
|
data.clear();
|
|
((DefaultTableModel) jTable.getModel()).fireTableDataChanged();
|
|
LoginPassModal lpm = new LoginPassModal(QueryClient.this);
|
|
lpm.setModal(true);
|
|
lpm.setVisible(true);
|
|
if (isCanceled()) {
|
|
setCanceled(false);
|
|
return;
|
|
}
|
|
DsClient dsClient = new DsClient(serviceAddress.getText());
|
|
try {
|
|
String sessionId = dsClient.userLogin(Configuration.DEFAULT_SESSION, getLogin(), getPasswd()).getSessionId();
|
|
List<Event> events = dsClient.eventLookup(sessionId, searchForm.getText(), null, null, null);
|
|
for (Event e : events) {
|
|
List<String> eventInfo = new ArrayList<String>();
|
|
eventInfo.add(e.getEventId() + "");
|
|
eventInfo.add(e.getObjectId());
|
|
eventInfo.add(e.getPartnerId());
|
|
eventInfo.add(e.getUserId());
|
|
eventInfo.add(e.getBizStep());
|
|
eventInfo.add(e.getEventType());
|
|
eventInfo.add(e.getEventClass());
|
|
eventInfo.add(e.getEventTimeStamp().toString());
|
|
eventInfo.add(e.getSourceTimeStamp().toString());
|
|
data.add(new Vector<String>(eventInfo));
|
|
((DefaultTableModel) jTable.getModel()).fireTableDataChanged();
|
|
}
|
|
dsClient.userLogout(sessionId);
|
|
JOptionPane.showInternalMessageDialog(QueryClient.this.getContentPane(), "event found: " + events.size() + "\nWarning: some events can be stored but not retrieved due to access control policy", "information", JOptionPane.INFORMATION_MESSAGE);
|
|
} catch (MalformedURIException ex) {
|
|
JOptionPane.showMessageDialog(QueryClient.this.getContentPane(), ex.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
|
|
} catch (EnhancedProtocolException ex) {
|
|
JOptionPane.showMessageDialog(QueryClient.this.getContentPane(), ex.getMessage(), "info", JOptionPane.ERROR_MESSAGE);
|
|
} catch (RemoteException ex) {
|
|
JOptionPane.showMessageDialog(QueryClient.this.getContentPane(), ex.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
|
|
}
|
|
}
|
|
});
|
|
j2.add(searchButton, BorderLayout.EAST);
|
|
j1.add(j2, BorderLayout.NORTH);
|
|
JScrollPane jScrollPane = new JScrollPane();
|
|
|
|
j1.add(jScrollPane, BorderLayout.CENTER);
|
|
List<String> tableName = new ArrayList<String>();
|
|
tableName.add("eventId");
|
|
tableName.add("objectId");
|
|
tableName.add("partnerId");
|
|
tableName.add("userId");
|
|
tableName.add("bizStep");
|
|
tableName.add("eventType");
|
|
tableName.add("eventClass");
|
|
tableName.add("eventTimeStamp");
|
|
tableName.add("sourceTimeStamp");
|
|
data = new Vector<Vector<String>>();
|
|
jTable = new JTable(data, new Vector<String>(tableName));
|
|
jScrollPane.setViewportView(jTable);
|
|
|
|
JPanel j4 = new JPanel();
|
|
j4.setLayout(new BorderLayout());
|
|
j4.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
|
|
JPanel j3 = new JPanel();
|
|
j3.setLayout(new BorderLayout());
|
|
j3.setBorder(BorderFactory.createTitledBorder("Service address"));
|
|
JLabel serviceAddressLabel = new JLabel(" Service address: ");
|
|
serviceAddress = new JTextField(DEFAULT_SERVICE_ADDRESS);
|
|
testButton = new JButton("Test service...");
|
|
testButton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent ae) {
|
|
DsClient dsClient = new DsClient(serviceAddress.getText());
|
|
try {
|
|
String serverId = dsClient.hello(Configuration.DEFAULT_SESSION);
|
|
JOptionPane.showInternalMessageDialog(QueryClient.this.getContentPane(), "serveur id: " + serverId, "information", JOptionPane.INFORMATION_MESSAGE);
|
|
} catch (EnhancedProtocolException ex) {
|
|
JOptionPane.showMessageDialog(QueryClient.this.getContentPane(), ex.getMessage(), "info", JOptionPane.ERROR_MESSAGE);
|
|
} catch (RemoteException ex) {
|
|
JOptionPane.showMessageDialog(QueryClient.this.getContentPane(), ex.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
|
|
}
|
|
}
|
|
});
|
|
j4.add(serviceAddressLabel, BorderLayout.WEST);
|
|
j4.add(serviceAddress, BorderLayout.CENTER);
|
|
j4.add(testButton, BorderLayout.EAST);
|
|
j3.add(j4, BorderLayout.CENTER);
|
|
this.getContentPane().add(j3, BorderLayout.NORTH);
|
|
}
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
// End of variables declaration//GEN-END:variables
|
|
}
|