use of com.example.entities.WorkItem in project aws-doc-sdk-examples by awsdocs.
the class MongoDBService method getListItemsReport.
// Retrieves all items from MongoDB
public ArrayList<WorkItem> getListItemsReport() {
MongoClient mongoClient = getConnection();
// Get the database name
DB database = mongoClient.getDB("local");
DBCursor cur = database.getCollection("items").find();
DBObject dbo = null;
ArrayList<WorkItem> itemList = new ArrayList();
WorkItem item = null;
int index = 0;
while (cur.hasNext()) {
index = 0;
item = new WorkItem();
dbo = cur.next();
Set<String> keys = dbo.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next();
String value = (String) dbo.get(key).toString();
if (key.compareTo("_id") == 0)
item.setId(value);
else if (key.compareTo("archive") == 0)
item.setArc(value);
else if (key.compareTo("date") == 0)
item.setDate(value);
else if (key.compareTo("description") == 0)
item.setDescription(value);
else if (key.compareTo("guide") == 0)
item.setGuide(value);
else if (key.compareTo("status") == 0)
item.setStatus(value);
else if (key.compareTo("username") == 0) {
item.setName(value);
// last item read
itemList.add(item);
}
}
}
return itemList;
}
use of com.example.entities.WorkItem in project aws-doc-sdk-examples by awsdocs.
the class MongoDBService method toXml.
// Convert Work item data into XML to pass back to the view.
private Document toXml(List<WorkItem> itemList) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
// Start building the XML.
Element root = doc.createElement("Items");
doc.appendChild(root);
// Get the elements from the collection.
int custCount = itemList.size();
// Iterate through the collection.
for (int index = 0; index < custCount; index++) {
// Get the WorkItem object from the collection.
WorkItem myItem = itemList.get(index);
Element item = doc.createElement("Item");
root.appendChild(item);
// Set Id.
Element id = doc.createElement("Id");
id.appendChild(doc.createTextNode(myItem.getId()));
item.appendChild(id);
// Set Name.
Element name = doc.createElement("Name");
name.appendChild(doc.createTextNode(myItem.getName()));
item.appendChild(name);
// Set Date.
Element date = doc.createElement("Date");
date.appendChild(doc.createTextNode(myItem.getDate()));
item.appendChild(date);
// Set Description.
Element desc = doc.createElement("Description");
desc.appendChild(doc.createTextNode(myItem.getDescription()));
item.appendChild(desc);
// Set Guide.
Element guide = doc.createElement("Guide");
guide.appendChild(doc.createTextNode(myItem.getGuide()));
item.appendChild(guide);
// Set Status.
Element status = doc.createElement("Status");
status.appendChild(doc.createTextNode(myItem.getStatus()));
item.appendChild(status);
}
return doc;
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
return null;
}
use of com.example.entities.WorkItem in project aws-doc-sdk-examples by awsdocs.
the class WriteExcel method createContent.
// Write the ItemData to the Excel report.
private int createContent(WritableSheet sheet, List<WorkItem> list) throws WriteException {
int size = list.size();
// Add data to the Excel report.
for (int i = 0; i < size; i++) {
WorkItem wi = list.get(i);
// Get the work item values.
String name = wi.getName();
String guide = wi.getGuide();
String date = wi.getDate();
String des = wi.getDescription();
String status = wi.getStatus();
// First column.
addLabel(sheet, 0, i + 2, name);
// Second column.
addLabel(sheet, 1, i + 2, date);
// Third column.
addLabel(sheet, 2, i + 2, guide);
// Forth column.
addLabel(sheet, 3, i + 2, des);
// Fifth column.
addLabel(sheet, 4, i + 2, status);
}
return size;
}
use of com.example.entities.WorkItem in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBService method getListItems.
// Retrieves items from the DynamoDB table.
public ArrayList<WorkItem> getListItems() {
// Create a DynamoDbEnhancedClient.
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(getClient()).build();
try {
// Create a DynamoDbTable object.
DynamoDbTable<Work> custTable = enhancedClient.table("Work", TableSchema.fromBean(Work.class));
// Get items in the Work table.
Iterator<Work> results = custTable.scan().items().iterator();
WorkItem workItem;
ArrayList<WorkItem> itemList = new ArrayList();
while (results.hasNext()) {
// Populate a WorkItem.
workItem = new WorkItem();
Work work = results.next();
workItem.setName(work.getName());
workItem.setGuide(work.getGuide());
workItem.setDescription(work.getDescription());
workItem.setStatus(work.getStatus());
workItem.setDate(work.getDate());
workItem.setId(work.getId());
// Push the workItem to the list.
itemList.add(workItem);
}
return itemList;
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done");
return null;
}
use of com.example.entities.WorkItem in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBService method getOpenItems.
// Get Open items from the DynamoDB table.
public String getOpenItems() {
// Create a DynamoDbEnhancedClient.
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(getClient()).build();
try {
// Create a DynamoDbTable object.
DynamoDbTable<Work> table = enhancedClient.table("Work", TableSchema.fromBean(Work.class));
AttributeValue attr = AttributeValue.builder().s("Open").build();
Map<String, AttributeValue> myMap = new HashMap<>();
myMap.put(":val1", attr);
Map<String, String> myExMap = new HashMap<>();
myExMap.put("#archive", "archive");
// Set the Expression so only Closed items are queried from the Work table.
Expression expression = Expression.builder().expressionValues(myMap).expressionNames(myExMap).expression("#archive = :val1").build();
ScanEnhancedRequest enhancedRequest = ScanEnhancedRequest.builder().filterExpression(expression).limit(15).build();
// Scan items.
Iterator<Work> results = table.scan(enhancedRequest).items().iterator();
WorkItem workItem;
ArrayList<WorkItem> itemList = new ArrayList();
while (results.hasNext()) {
// Populate a WorkItem.
workItem = new WorkItem();
Work work = results.next();
workItem.setName(work.getName());
workItem.setGuide(work.getGuide());
workItem.setDescription(work.getDescription());
workItem.setStatus(work.getStatus());
workItem.setDate(work.getDate());
workItem.setId(work.getId());
// Push the workItem to the list.
itemList.add(workItem);
}
return convertToString(toXml(itemList));
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done");
return "";
}
Aggregations