use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DElement method applyChanges.
protected void applyChanges() {
if (isRemoved_) {
// NTF there's no point in applying changes to an element that's been removed.
return;
}
Map<String, Object> props = getProps();
Map<String, Object> delegate = getDelegate();
if (delegate == null) {
throw new IllegalStateException("Get delegate returned null for id " + getId() + " so we cannot apply changes to it.");
}
boolean saveNeeded = false;
Set<String> changes = getChangedPropertiesInt();
if (!props.isEmpty() && !changes.isEmpty()) {
saveNeeded = true;
// System.out.println("TEMP DEBUG: Writing " + getChangedPropertiesInt().size() + " changed properties for " + getId());
for (String s : changes) {
String key = s;
Object v = props.get(key);
// System.out.println("TEMP DEBUG: Writing a " + v.getClass().getSimpleName() + " to " + key);
if (s != null && v != null) {
if (s.startsWith(DVertex.IN_PREFIX) || s.startsWith(DVertex.OUT_PREFIX)) {
if (delegate instanceof Document) {
if (v instanceof NoteList) {
byte[] bytes = ((NoteList) v).toByteArray();
((Document) delegate).writeBinary(s, bytes, 2048 * 24);
// FIXME NTF .writeBinary needs to clear any extra items added to the document if the binary content shrank
// System.out.println("TEMP DEBUG: Writing a NoteList (" + ((NoteList) v).size() + ") of size " + bytes.length
// + " to a Document in " + s);
} else {
((Document) delegate).replaceItemValue(s, v, false);
((Document) delegate).closeMIMEEntities(true);
}
} else {
try {
delegate.put(s, v);
} catch (Throwable t) {
System.err.println("ALERT Failed to write a property of " + s + " to element id " + getId() + " which has a delegate of type " + delegate.getClass().getName() + " due to a " + t.getClass().getSimpleName());
t.printStackTrace();
}
}
} else {
try {
delegate.put(s, v);
} catch (Throwable t) {
System.err.println("ALERT Failed to write a property of " + s + " to element id " + getId() + " due to a " + t.getClass().getSimpleName());
t.printStackTrace();
}
}
}
}
getChangedPropertiesInt().clear();
} else {
// System.out.println("TEMP ALERT: No changed properties for element " + getId());
}
for (String key : getRemovedPropertiesInt()) {
delegate.remove(key);
saveNeeded = true;
}
getRemovedPropertiesInt().clear();
if (delegate instanceof Document) {
if (saveNeeded) {
Document doc = (Document) delegate;
// if (!doc.hasItem("form")) {
// System.err.println("Graph element being saved without a form value.");
// }
doc.save();
}
}
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DElementStore method findElementDelegate.
// @Override
@Override
public Object findElementDelegate(final Object delegateKey) throws IllegalStateException, IllegalArgumentException {
Object result = null;
Object del = null;
del = getStoreDelegate();
if (isProxied()) {
// System.out.println("TEMP DEBUG Retrieving from proxied store for key " + String.valueOf(delegateKey));
NoteCoordinate nc = null;
if (delegateKey instanceof NoteCoordinate) {
nc = (NoteCoordinate) delegateKey;
} else if (delegateKey instanceof CharSequence) {
nc = NoteCoordinate.Utils.getNoteCoordinate((CharSequence) delegateKey);
}
if (nc != null) {
long dbkey = nc.getReplicaLong();
if (getProxyStoreKey().equals(dbkey)) {
del = getProxyStoreDelegate();
}
}
}
if (del instanceof Database) {
Database db = (Database) del;
boolean isDeletedDoc;
db.getAncestorSession().setFixEnable(Fixes.MIME_BLOCK_ITEM_INTERFACE, false);
if (delegateKey instanceof Serializable) {
if (delegateKey instanceof ViewEntryCoordinate) {
result = ((ViewEntryCoordinate) delegateKey).getViewEntry();
} else if (delegateKey instanceof NoteCoordinate) {
String unid = ((NoteCoordinate) delegateKey).getUNID();
try {
result = db.getDocumentWithKey(unid, false);
} catch (UserAccessException uae) {
// this is normal and acceptable. Don't report.
} catch (RuntimeException re) {
throw re;
}
if (result != null) {
if (((Document) result).isDeleted()) {
isDeletedDoc = true;
result = null;
}
}
// System.out.println("Retrieved result using NoteCoordinate with unid " + unid);
} else if (delegateKey instanceof CharSequence) {
String skey = ((CharSequence) delegateKey).toString();
if (skey.length() > 50) {
String prefix = skey.subSequence(0, 2).toString();
String mid = skey.subSequence(2, 50).toString();
if ((prefix.equals("EC") || prefix.equals("ED") || prefix.equals("ET") || prefix.equals("EU")) && DominoUtils.isMetaversalId(mid)) {
ViewEntryCoordinate vec = ViewEntryCoordinate.Utils.getViewEntryCoordinate(skey);
result = vec.getViewEntry();
} else if ((prefix.equals("VC") || prefix.equals("VD") || prefix.equals("VT") || prefix.equals("VU")) && DominoUtils.isMetaversalId(mid)) {
ViewEntryCoordinate vec = ViewEntryCoordinate.Utils.getViewEntryCoordinate(skey);
result = vec.getViewEntry();
}
}
}
if (result == null) {
result = db.getDocumentWithKey((Serializable) delegateKey, false);
if (result != null) {
if (((Document) result).isDeleted()) {
isDeletedDoc = true;
result = null;
}
}
}
if (result != null) {
// }
if (isProxied()) {
// System.out.println("TEMP DEBUG from findElementDelegate: ElementStore "
// + ((Database) getStoreDelegate()).getApiPath() + "is proxied. Setting up proxy on delegate...");
result = setupProxy(result, (Serializable) delegateKey);
} else {
// System.out.println("TEMP DEBUG ElementStore " + ((Database) getStoreDelegate()).getApiPath() + " is not proxied.");
}
}
} else {
if (delegateKey != null) {
System.out.println("WARNING: Unknown delegatekey of type " + delegateKey.getClass().getName() + ". Creating a brand new delegate.");
}
// null is a perfectly valid key, since it means we want to let the system assign it.
result = db.createDocument();
// throw new IllegalArgumentException("Cannot find a delegate with a key of type "
// + (delegateKey == null ? "null" : delegateKey.getClass().getName()));
}
} else {
throw new IllegalStateException("ElementStore delegate is not a Database; it's a " + (del == null ? "null" : del.getClass().getName()) + ". We don't handle this case yet.");
// TODO NTF alternative strategies...
}
// }
return result;
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DElementStore method setupProxy.
@SuppressWarnings("unchecked")
protected DProxyVertex setupProxy(final Object proxy, final Serializable originalKey) {
// System.out.println("TEMP DEBUG Setting up proxy vertex");
DProxyVertex result = new DProxyVertex(getConfiguration().getGraph(), (Map<String, Object>) proxy);
Object rawpid = result.getProxiedId();
if (rawpid != null) {
if (result.getProxyDelegate() == null) {
DElement elem = (DElement) getConfiguration().getGraph().getElement(rawpid);
if (elem == null) {
rawpid = null;
}
}
}
if (rawpid == null) {
CustomProxyResolver resolver = getCustomProxyResolver();
if (resolver == null) {
System.err.println("No default resolver implemented yet");
throw new UnimplementedException("Generics resolution of proxied vertices not yet implemented");
} else {
// System.out.println("Resolving using a " + resolver.getClass().getName());
Map<String, Object> originalDelegate = resolver.getOriginalDelegate(originalKey);
if (originalDelegate instanceof Document) {
String pid = ((Document) originalDelegate).getMetaversalID();
NoteCoordinate nc = NoteCoordinate.Utils.getNoteCoordinate(pid);
// System.out.println("Setting up proxy with id " + nc.toString());
try {
result.setProxiedId(nc);
} catch (Throwable t) {
t.printStackTrace();
}
} else {
if (originalDelegate == null) {
// System.out.println("No original delegate found for key " + String.valueOf(originalKey));
} else {
// System.err.println("original delegate returned a " + originalDelegate.getClass().getName());
}
}
}
} else {
}
// System.out.println("Setup a proxy with an id of " + String.valueOf(result.getProxiedId()));
return result;
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DElementStore method wrapProxiedVertex.
public DProxyVertex wrapProxiedVertex(final Map<String, Object> delegate) {
// System.out.println("Wrapping a proxied vertex...");
DVertex vertex = new DVertex(getConfiguration().getGraph(), delegate);
Object pDelegate = getProxyStoreDelegate();
Serializable pKey = null;
Map<String, Object> proxyDelegate = null;
pKey = getKeyProperty(delegate);
if (pKey == null) {
if (delegate instanceof Document) {
pKey = ((Document) delegate).getMetaversalID();
} else {
// TODO future implementations...
}
}
if (pDelegate instanceof Database) {
Database pDb = ((Database) pDelegate);
// System.out.println("Creating proxy version in database " + pDb.getApiPath());
Document pDoc = pDb.getDocumentWithKey(pKey, true);
if (pDoc != null && pDoc.isNewNote()) {
pDoc.save();
}
proxyDelegate = pDoc;
} else {
// TODO future implementations...
}
DProxyVertex result = new DProxyVertex(getConfiguration().getGraph(), vertex, proxyDelegate);
return result;
}
use of org.openntf.domino.Document in project org.openntf.domino by OpenNTF.
the class DFramedTransactionalGraph method frame.
public <F> F frame(final Vertex vertex, Class<F> kind, final boolean temporary) {
if (vertex == null) {
return null;
}
if (vertex instanceof DCategoryVertex) {
kind = (Class<F>) CategoryVertex.class;
} else {
Map map = ((DVertex) vertex).getDelegate();
if (map instanceof Document) {
if (DesignFactory.isView((Document) map)) {
kind = (Class<F>) ViewVertex.class;
}
if (DesignFactory.isIcon((Document) map) || DesignFactory.isACL((Document) map)) {
// System.out.println("TEMP DEBUG framing an icon note");
kind = (Class<F>) DbInfoVertex.class;
}
}
}
DConfiguration config = (DConfiguration) this.getConfig();
Class<F> klazz = (Class<F>) (kind == null ? config.getDefaultVertexFrameType() : kind);
if (config.getReplacementType(klazz) != null) {
klazz = (Class<F>) config.getReplacementType(klazz);
}
DTypeManager manager = config.getTypeManager();
klazz = (Class<F>) manager.initElement(klazz, this, vertex, temporary);
for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
if (!(initializer instanceof JavaFrameInitializer)) {
initializer.initElement(klazz, this, vertex);
}
}
F result = null;
try {
result = super.frame(vertex, klazz);
} catch (Throwable t) {
System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
t.printStackTrace();
// DominoUtils.handleException(e);
try {
result = (F) super.frame(vertex, config.getDefaultVertexFrameType());
} catch (Exception e) {
System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
e.printStackTrace();
DominoUtils.handleException(e);
}
}
for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
if (initializer instanceof JavaFrameInitializer) {
((JavaFrameInitializer) initializer).initElement(klazz, this, result);
}
}
if (vertex instanceof DProxyVertex) {
List<CaseInsensitiveString> proxied = config.getTypeRegistry().getProxied(klazz);
if (proxied != null) {
((DProxyVertex) vertex).setProxied(proxied);
}
}
if (result instanceof Eventable) {
if (((Eventable) result).isNew()) {
try {
// $NON-NLS-1$
Method crystal = result.getClass().getMethod("create");
if (crystal != null) {
((Eventable) result).create();
}
} catch (Throwable t) {
// nothing
}
} else {
// try {
// Method crystal = result.getClass().getMethod("read", null);
// if (crystal != null) {
// ((Eventable) result).read();
// }
// } catch (Throwable t) {
// //nothing
// }
}
}
return result;
}
Aggregations