use of org.openntf.domino.DateTime in project org.openntf.domino by OpenNTF.
the class AbstractDesignAgent method getLastRunDuration.
@Override
public Long getLastRunDuration() {
List<String> lastRunLog = getRunLogAsList();
if (!lastRunLog.isEmpty()) {
// $NON-NLS-1$
String strStart = "";
// $NON-NLS-1$
String strEnd = "";
try {
for (String str : lastRunLog) {
if (Strings.startsWithIgnoreCase(str, "Started running agent")) {
// $NON-NLS-1$
strStart = str.substring(str.length() - 19, str.length());
if (strStart.contains("AM") || strStart.contains("PM")) {
// $NON-NLS-1$ //$NON-NLS-2$
strStart = str.substring(str.length() - 22, str.length() - 3);
}
} else if (Strings.startsWithIgnoreCase(str, "Done running agent")) {
// $NON-NLS-1$
strEnd = str.substring(str.length() - 19, str.length());
if (strEnd.contains("AM") || strEnd.contains("PM")) {
// $NON-NLS-1$ //$NON-NLS-2$
strEnd = str.substring(str.length() - 22, str.length() - 3);
}
}
}
if (strStart == "" || strEnd == "") {
// $NON-NLS-1$ //$NON-NLS-2$
return Long.MIN_VALUE;
}
// Adjust for pre-2000 dates, which don't have four-digit year
if ("/9".equals(strStart.substring(7, 9))) {
// $NON-NLS-1$
strStart = strStart.substring(2);
}
if ("/9".equals(strEnd.substring(7, 9))) {
// $NON-NLS-1$
strEnd = strEnd.substring(2);
}
DateTime start = Factory.getSession(SessionType.CURRENT).createDateTime(strStart);
DateTime end = Factory.getSession(SessionType.CURRENT).createDateTime(strEnd);
Calendar thisCal = start.toJavaCal();
Calendar thatCal = end.toJavaCal();
return (thatCal.getTimeInMillis() - thisCal.getTimeInMillis()) / 1000;
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
DominoUtils.handleException(e, "Error on " + getName() + " - start: " + strStart + ", end: " + strEnd);
}
}
return Long.MIN_VALUE;
}
use of org.openntf.domino.DateTime in project org.openntf.domino by OpenNTF.
the class ItemDefinition method createDefaultItem.
@Override
public Item createDefaultItem(final Document doc, final DocumentDefinition def) {
String name = getName();
Object defaultValue = getDefaultValue();
if (defaultValue == null) {
Class<?> checkType = getType();
if (checkType.isArray()) {
checkType = getType().getComponentType();
}
if (checkType == Integer.TYPE || checkType.equals(Integer.class)) {
defaultValue = 0;
} else if (checkType == Long.TYPE || checkType.equals(Long.class)) {
defaultValue = 0;
} else if (checkType == Double.TYPE || checkType.equals(Double.class)) {
defaultValue = 0;
} else if (checkType == Float.TYPE || checkType.equals(Float.class)) {
defaultValue = 0;
} else if (checkType == Short.TYPE || checkType.equals(Short.class)) {
defaultValue = 0;
} else if (checkType == Long.TYPE || checkType.equals(Long.class)) {
defaultValue = 0;
} else if (checkType.equals(String.class)) {
// $NON-NLS-1$
defaultValue = "";
} else if (checkType.equals(DateTime.class)) {
DateTime dt = doc.getAncestorSession().createDateTime(new Date());
dt.setAnyDate();
dt.setAnyTime();
defaultValue = dt;
} else {
defaultValue = null;
}
}
Item item = null;
if (defaultValue != null) {
item = doc.replaceItemValue(name, defaultValue);
} else {
try {
// $NON-NLS-1$
item = doc.replaceItemValueCustomDataBytes(name, "", new byte[1]);
} catch (IOException e) {
DominoUtils.handleException(e);
}
}
if (item != null) {
if (!def.isDefaultSummary()) {
item.setSummary(false);
}
for (Flags flag : getFlags()) {
switch(flag) {
case SUMMARY:
item.setSummary(true);
break;
case AUTHORS:
item.setAuthors(true);
break;
case READERS:
item.setReaders(true);
break;
case PROTECTED:
item.setProtected(true);
break;
case SIGNED:
item.setSigned(true);
break;
case ENCRYPTED:
item.setEncrypted(true);
break;
}
}
}
return item;
}
use of org.openntf.domino.DateTime in project org.openntf.domino by OpenNTF.
the class ElementComparator method compareStrs.
@SuppressWarnings({ "rawtypes", "unchecked" })
private int compareStrs(final IDominoElement arg0, final IDominoElement arg1) {
int result = 0;
for (String key : props_) {
java.lang.Object v0 = DominoElement.getReflectiveProperty(arg0, key);
java.lang.Object v1 = DominoElement.getReflectiveProperty(arg1, key);
if (v0 == null && v1 == null) {
result = 0;
} else if (v0 == null) {
return -1;
} else if (v1 == null) {
return 1;
}
if (v0 instanceof Number && v1 instanceof Number) {
double d0 = ((Number) v0).doubleValue();
double d1 = ((Number) v1).doubleValue();
if (d0 > d1) {
result = 1;
} else if (d1 > d0) {
result = -1;
}
} else if (v0 instanceof String && v1 instanceof String) {
String s0 = (String) v0;
String s1 = (String) v1;
if (caseSensitive_) {
result = s0.compareTo(s1);
} else {
result = s0.compareToIgnoreCase(s1);
}
} else if (v0 instanceof Date && v1 instanceof Date) {
Date d0 = (Date) v0;
Date d1 = (Date) v1;
result = d0.compareTo(d1);
} else if (v0 instanceof DateTime && v1 instanceof DateTime) {
DateTime d0 = (DateTime) v0;
DateTime d1 = (DateTime) v1;
result = d0.compareTo(d1);
} else if (v0 != null && v1 != null) {
if (v0 instanceof Comparable && v1 instanceof Comparable) {
result = ((Comparable) v0).compareTo(v1);
}
}
if (result != 0) {
break;
}
}
if (result == 0) {
result = ((Comparable) arg0.getId()).compareTo(arg1.getId());
// if (result == 0) {
// System.out.println("Element comparator still ended up with match!??!");
// result = -1;
// }
}
return result;
}
use of org.openntf.domino.DateTime in project org.openntf.domino by OpenNTF.
the class Connect17Documents method run.
@Override
public void run() {
Session sess = Factory.getSession(SessionType.NATIVE);
Database extLib = sess.getDatabase("odademo/oda_1.nsf");
View contacts = extLib.getView("AllContacts");
View threads = extLib.getView("AllThreadsByAuthor");
Document doc = contacts.getFirstDocument();
// Clears changes this function already made
resetDoc(doc);
Document newDoc = extLib.createDocument();
doc.copyAllItems(newDoc, true);
String prevDocAsJson = doc.toJson(true);
doc.appendItemValue("State", "AZ");
doc.replaceItemValue("DateTimeField", new Date());
doc.replaceItemValue("DateOnlyField", new java.sql.Date(System.currentTimeMillis()));
System.out.println(doc.getFirstItem("DateOnlyField").getValues());
doc.replaceItemValue("TimeOnlyField", new java.sql.Time(System.currentTimeMillis()));
System.out.println(doc.getFirstItem("TimeOnlyField").getValues());
doc.replaceItemValue("EmptyDate", "");
Date blankDate = doc.getItemValue("EmptyDate", Date.class);
System.out.println(blankDate);
ArrayList<String> list = new ArrayList<String>();
list.add("Value 1");
list.add("Value 2");
doc.replaceItemValue("MVField", list);
doc.replaceItemValue("DocAsJson", prevDocAsJson);
HashMap<String, String> mapField = new HashMap<String, String>();
DocumentCollection dc = threads.getAllDocumentsByKey(doc.getItemValueString("FullName"));
for (Document tmp : dc) {
mapField.put(tmp.getUniversalID(), tmp.getItemValueString("Title"));
}
doc.put("MapField", mapField);
BigDecimal decimal = new BigDecimal("2.5");
doc.replaceItemValue("BigDecimalField", decimal);
doc.replaceItemValue("EnumField", Fixes.FORCE_HEX_LOWER_CASE);
doc.save();
HashMap tmp = doc.getItemValue("MapField", HashMap.class);
System.out.println(tmp.size());
System.out.println(doc.getMetaversalID());
System.out.println(doc.getItemValueString("EnumField"));
java.sql.Date sqlDt = doc.getItemValue("DateTimeField", java.sql.Date.class);
System.out.println(sqlDt);
java.sql.Time sqlTime = doc.getItemValue("DateTimeField", java.sql.Time.class);
System.out.println(sqlTime);
System.out.println(doc.getItemValues("BigDecimalField", BigDecimal.class));
System.out.println(doc.getFirstItem("MVField").getTypeEx());
ArrayList<String> blank = new ArrayList<String>();
doc.replaceItemValue("MVField", blank);
System.out.println(doc.hasItem("MVField"));
NamesList names = new NamesList();
names.add("CN=Paul Withers/O=Intec");
names.add("CN=Admin/O=Intec=PW");
newDoc.replaceItemValue("Names", names);
AuthorsList authors = new AuthorsList();
authors.addAll(names);
newDoc.replaceItemValue("Authors", authors);
ReadersList readers = new ReadersList();
readers.addAll(names);
newDoc.replaceItemValue("Readers", readers);
Item dt = newDoc.replaceItemValue("TestDate", "");
Vector<DateTime> dates = new Vector();
DateTime dt1 = sess.createDateTime("01/01/2017");
DateTime dt2 = sess.createDateTime("02/01/2017");
dates.add(dt1);
dates.add(dt2);
dt.setValues(dates);
newDoc.save();
}
use of org.openntf.domino.DateTime in project org.openntf.domino by OpenNTF.
the class JsonGraphWriter method outDominoValue.
public void outDominoValue(final Object paramObject) throws IOException {
try {
if (paramObject == null) {
outNull();
return;
}
if (paramObject instanceof String) {
outStringLiteral((String) paramObject);
return;
}
if (paramObject instanceof Number) {
outNumberLiteral(((Number) paramObject).doubleValue());
return;
}
if (paramObject instanceof Boolean) {
outBooleanLiteral(((Boolean) paramObject).booleanValue());
return;
}
if (paramObject instanceof Date) {
outStringLiteral(dateToString((Date) paramObject, true));
return;
}
if (paramObject instanceof DateTime) {
if (((DateTime) paramObject).getDateOnly().length() == 0) {
outStringLiteral(timeOnlyToString(((DateTime) paramObject).toJavaDate()));
return;
}
if (((DateTime) paramObject).getTimeOnly().length() == 0) {
outStringLiteral(dateOnlyToString(((DateTime) paramObject).toJavaDate()));
return;
}
outStringLiteral(dateToString(((DateTime) paramObject).toJavaDate(), true));
return;
}
if (paramObject instanceof Vector) {
startArray();
Vector localVector = (Vector) paramObject;
int i = localVector.size();
for (int j = 0; j < i; ++j) {
startArrayItem();
outDominoValue(localVector.get(j));
endArrayItem();
}
endArray();
return;
}
outStringLiteral("???");
} catch (JsonException localJsonException) {
throw new AbstractIOException(localJsonException, "");
}
}
Aggregations