List of usage examples for java.util.logging Level FINEST
Level FINEST
To view the source code for java.util.logging Level FINEST.
Click Source Link
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Link updateLink(String wskey, String path, String target) throws CoreServiceException, InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "updating link into workspace [" + wskey + "] at path [" + path + "]"); try {/*from w w w. ja v a 2 s . com*/ PathBuilder npath = PathBuilder.fromPath(path); if (npath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder ppath = npath.clone().parent(); String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException( "unable to update link in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "update"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'update' permission on the head collection of this workspace"); String current = resolveWorkspacePath(wskey, Workspace.HEAD, npath.build()); OrtolangObjectIdentifier cidentifier = registry.lookup(current); checkObjectType(cidentifier, Link.OBJECT_TYPE); Link clink = em.find(Link.class, cidentifier.getId()); if (clink == null) { throw new CoreServiceException( "unable to load link with id [" + cidentifier.getId() + "] from storage"); } clink.setKey(current); LOGGER.log(Level.FINEST, "current link loaded"); String ntarget = PathBuilder.fromPath(target).build(); if (!ntarget.equals(clink.getTarget())) { Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); LOGGER.log(Level.FINEST, "parent collection loaded for path " + npath.build()); CollectionElement element = parent.findElementByName(npath.part()); if (element == null) { throw new PathNotFoundException(npath.build()); } LOGGER.log(Level.FINEST, "link element found for name " + npath.part()); if (!element.getType().equals(Link.OBJECT_TYPE)) { throw new InvalidPathException("path [" + npath.build() + "] is not a link"); } OrtolangObjectIdentifier identifier = registry.lookup(element.getKey()); checkObjectType(identifier, Link.OBJECT_TYPE); Link link = em.find(Link.class, identifier.getId()); if (link == null) { throw new CoreServiceException( "unable to load link with id [" + identifier.getId() + "] from storage"); } link.setKey(element.getKey()); link.setTarget(ntarget); if (link.getClock() < ws.getClock()) { Link clone = cloneLink(ws.getHead(), link, ws.getClock()); parent.removeElement(element); CollectionElement celement = new CollectionElement(Link.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, clone.getKey()); parent.addElement(celement); link = clone; } em.merge(parent); em.merge(link); registry.update(parent.getKey()); registry.update(link.getKey()); indexing.index(link.getKey()); LOGGER.log(Level.FINEST, "link updated"); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(4).addArgument("ws-alias", ws.getAlias()) .addArgument("key", link.getKey()).addArgument("okey", element.getKey()) .addArgument("path", npath.build()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Link.OBJECT_TYPE, "update"), argsBuilder.build()); return link; } else { LOGGER.log(Level.FINEST, "no changes detected with current link, nothing to do"); return clink; } } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException | AuthorisationServiceException | MembershipServiceException | CloneException | IndexingServiceException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred while updating link", e); throw new CoreServiceException( "unable to update link into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Link moveLink(String wskey, String source, String destination) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "moving link into workspace [" + wskey + "] from path [" + source + "] to path [" + destination + "]"); try {//from w w w .j a v a 2s. c om PathBuilder spath = PathBuilder.fromPath(source); if (spath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder sppath = spath.clone().parent(); PathBuilder dpath = PathBuilder.fromPath(destination); if (dpath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder dppath = dpath.clone().parent(); if (dpath.equals(spath)) { throw new InvalidPathException("unable to move into the same path"); } if (spath.isParent(dpath)) { throw new InvalidPathException("unable to move into a children of this path"); } String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException( "unable to move link in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "update"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'update' permission on the head collection of this workspace"); Collection sparent = loadCollectionAtPath(ws.getHead(), sppath, ws.getClock()); CollectionElement selement = sparent.findElementByName(spath.part()); if (selement == null) { throw new PathNotFoundException(spath.build()); } LOGGER.log(Level.FINEST, "source link element found for name " + spath.part()); OrtolangObjectIdentifier slidentifier = registry.lookup(selement.getKey()); checkObjectType(slidentifier, Link.OBJECT_TYPE); Link slink = em.find(Link.class, slidentifier.getId()); if (slink == null) { throw new CoreServiceException( "unable to load source link with id [" + slidentifier.getId() + "] from storage"); } slink.setKey(selement.getKey()); LOGGER.log(Level.FINEST, "source link exists and loaded from storage"); Collection dparent = loadCollectionAtPath(ws.getHead(), dppath, ws.getClock()); if (dparent.containsElementName(dpath.part())) { throw new PathAlreadyExistsException(dpath.build()); } sparent.removeElement(selement); em.merge(sparent); registry.update(sparent.getKey()); indexing.index(sparent.getKey()); LOGGER.log(Level.FINEST, "parent [" + sparent.getKey() + "] has been updated"); if (!dpath.part().equals(spath.part())) { if (slink.getClock() < ws.getClock()) { slink = cloneLink(ws.getHead(), slink, ws.getClock()); } slink.setName(dpath.part()); em.merge(slink); registry.update(slink.getKey()); indexing.index(slink.getKey()); } dparent.addElement(new CollectionElement(Link.OBJECT_TYPE, slink.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, slink.getKey())); em.merge(dparent); registry.update(dparent.getKey()); indexing.index(dparent.getKey()); LOGGER.log(Level.FINEST, "link [" + slink.getKey() + "] added to destination parent [" + dparent.getKey() + "]"); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias()) .addArgument("key", slink.getKey()).addArgument("okey", selement.getKey()) .addArgument("src-path", spath.build()).addArgument("dest-path", dpath.build()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Link.OBJECT_TYPE, "move"), argsBuilder.build()); return slink; } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | CloneException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error while moving link", e); throw new CoreServiceException("unable to move link into workspace [" + wskey + "] from path [" + source + "] to path [" + destination + "]", e); } }
From source file:edu.umass.cs.reconfiguration.Reconfigurator.java
/** * This method issues reconfigurations for records replicated on active in a * manner that limits the number of outstanding reconfigurations using the * {@link #outstandingReconfigurations} queue. *//*from ww w. j a v a2s .co m*/ @SuppressWarnings({ "unchecked" }) private boolean deleteActiveReplica(NodeIDType active, InetSocketAddress creator) { boolean initiated = this.DB.app.initiateReadActiveRecords(active); if (!initiated) { log.log(Level.WARNING, "{0} deleteActiveReplica {1} unable to initiate read active records", new Object[] { this, active }); return false; } int rcCount = 0; // this.setOutstanding(active); this.consistentNodeConfig.slateForRemovalActive(active); ReconfigurationRecord<NodeIDType> record = null; while ((record = this.DB.app.readNextActiveRecord()) != null) { log.log(Level.FINEST, "{0} reconfiguring {1} in order to delete active {1}", new Object[] { this, record.getName(), active }); try { this.DB.waitOutstanding(MAX_OUTSTANDING_RECONFIGURATIONS); } catch (InterruptedException e) { e.printStackTrace(); return false; } // reconfigure name so as to exclude active Set<NodeIDType> newActives = new HashSet<NodeIDType>(record.getActiveReplicas()); assert (newActives.contains(active)); NodeIDType newActive = (NodeIDType) Util .getRandomOtherThan(this.consistentNodeConfig.getActiveReplicas(), newActives); if (newActive != null) newActives.add(newActive); newActives.remove(active); if (this.initiateReconfiguration(record.getName(), record, newActives, creator, null, null, null, null, null)) { rcCount++; this.DB.addToOutstanding(record.getName()); record = this.DB.getReconfigurationRecord(record.getName()); if (record != null && record.getActiveReplicas() != null && !record.getActiveReplicas().contains(active)) // inelegant redundant check to handle concurrency this.DB.notifyOutstanding(record.getName()); } } log.log(Level.INFO, "{0} closing read active records cursor after initiating " + "{1} reconfigurations in order to delete active {2}", new Object[] { this, rcCount, active }); boolean closed = this.DB.app.closeReadActiveRecords(); // this.setNoOutstanding(); return initiated && closed; }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteLink(String wskey, String path) throws CoreServiceException, KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "deleting link into workspace [" + wskey + "] at path [" + path + "]"); try {//from w w w . j av a 2s .c om PathBuilder npath = PathBuilder.fromPath(path); if (npath.isRoot()) { throw new InvalidPathException("path is empty"); } PathBuilder ppath = npath.clone().parent(); String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException( "unable to delete link in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "delete"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'delete' permission on the head collection of this workspace"); Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); CollectionElement element = parent.findElementByName(npath.part()); if (element == null) { throw new PathNotFoundException(npath.build()); } LOGGER.log(Level.FINEST, "link element found for name " + npath.part()); OrtolangObjectIdentifier lidentifier = registry.lookup(element.getKey()); checkObjectType(lidentifier, Link.OBJECT_TYPE); Link leaf = em.find(Link.class, lidentifier.getId()); if (leaf == null) { throw new CoreServiceException( "unable to load link with id [" + lidentifier.getId() + "] from storage"); } leaf.setKey(element.getKey()); LOGGER.log(Level.FINEST, "link exists and loaded from storage"); parent.removeElement(element); em.merge(parent); registry.update(parent.getKey()); indexing.index(parent.getKey()); LOGGER.log(Level.FINEST, "parent [" + parent.getKey() + "] has been updated"); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); if (leaf.getClock() == ws.getClock()) { LOGGER.log(Level.FINEST, "leaf clock [" + leaf.getClock() + "] is the same than workspace, key can be deleted and unindexed"); for (MetadataElement mde : leaf.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(leaf.getKey()); indexing.remove(leaf.getKey()); } ArgumentsBuilder argsBuilder = new ArgumentsBuilder(3).addArgument("ws-alias", ws.getAlias()) .addArgument("key", leaf.getKey()).addArgument("path", npath.build()); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Link.OBJECT_TYPE, "delete"), argsBuilder.build()); } catch (KeyLockedException | NotificationServiceException | RegistryServiceException | MembershipServiceException | AuthorisationServiceException | IndexingServiceException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error while deleting link", e); throw new CoreServiceException( "unable to delete link into workspace [" + wskey + "] at path [" + path + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public MetadataObject createMetadataObject(String wskey, String key, String path, String name, String hash, String filename, boolean purgeChildren) throws CoreServiceException, KeyAlreadyExistsException, InvalidPathException, MetadataFormatException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "create metadataobject with key [" + key + "] into workspace [" + wskey + "] for path [" + path + "] with name [" + name + "]"); try {/*from w ww.jav a2 s. com*/ PathBuilder npath = PathBuilder.fromPath(path); PathBuilder ppath = npath.clone().parent(); String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException("unable to create metadata object in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "create"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'create' permission on the head collection of this workspace"); String tkey; Collection parent = null; CollectionElement element = null; if (npath.isRoot()) { tkey = ws.getHead(); } else { parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build()); element = parent.findElementByName(npath.part()); if (element == null) { throw new PathNotFoundException(npath.build()); } LOGGER.log(Level.FINEST, "collection element found for name " + npath.part()); tkey = element.getKey(); } OrtolangObjectIdentifier tidentifier = registry.lookup(tkey); if (!tidentifier.getType().equals(Link.OBJECT_TYPE) && !tidentifier.getType().equals(Collection.OBJECT_TYPE) && !tidentifier.getType().equals(DataObject.OBJECT_TYPE)) { throw new CoreServiceException("metadata target can only be a Link, a DataObject or a Collection."); } MetadataObject meta = new MetadataObject(); meta.setId(UUID.randomUUID().toString()); meta.setName(name); MetadataFormat format = getMetadataFormat(name); if (format == null) { LOGGER.log(Level.SEVERE, "Unable to find a metadata format for name: " + name); throw new CoreServiceException("unknown metadata format for name: " + name); } if (hash != null && hash.length() > 0) { if (format.isValidationNeeded()) { validateMetadata(hash, format); } meta.setSize(binarystore.size(hash)); if (filename != null) { meta.setContentType(binarystore.type(hash, filename)); } else { meta.setContentType(binarystore.type(hash)); } meta.setStream(hash); } else { meta.setSize(0); meta.setContentType("application/octet-stream"); meta.setStream(""); } meta.setFormat(format.getId()); meta.setTarget(tkey); meta.setKey(key); em.persist(meta); Properties properties = new Properties(); properties.put(WORKSPACE_REGISTRY_PROPERTY_KEY, wskey); registry.register(key, meta.getObjectIdentifier(), caller, properties); authorisation.clonePolicy(key, ws.getHead()); switch (tidentifier.getType()) { case Collection.OBJECT_TYPE: Collection collection = em.find(Collection.class, tidentifier.getId()); if (collection == null) { ctx.setRollbackOnly(); throw new CoreServiceException( "unable to load collection with id [" + tidentifier.getId() + "] from storage"); } collection.setKey(tkey); for (MetadataElement mde : collection.getMetadatas()) { if (mde.getName().equals(name)) { ctx.setRollbackOnly(); throw new CoreServiceException("a metadata object with name [" + name + "] already exists for collection at path [" + npath.build() + "]"); } } if (collection.getClock() < ws.getClock()) { Collection clone = cloneCollection(ws.getHead(), collection, ws.getClock()); tkey = clone.getKey(); meta.setTarget(tkey); if (parent != null) { parent.removeElement(element); parent.addElement(new CollectionElement(Collection.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Collection.MIME_TYPE, clone.getKey())); em.merge(parent); registry.update(parent.getKey()); } collection = clone; } collection.addMetadata(new MetadataElement(name, key)); em.merge(collection); if (purgeChildren) { LOGGER.log(Level.FINE, "Purging children metadata"); purgeChildrenMetadata(collection, wskey, path, name); } break; case DataObject.OBJECT_TYPE: DataObject object = em.find(DataObject.class, tidentifier.getId()); if (object == null) { ctx.setRollbackOnly(); throw new CoreServiceException( "unable to load object with id [" + tidentifier.getId() + "] from storage"); } object.setKey(tkey); for (MetadataElement mde : object.getMetadatas()) { if (mde.getName().equals(name)) { ctx.setRollbackOnly(); throw new CoreServiceException("a metadata object with name [" + name + "] already exists for object at path [" + npath.build() + "]"); } } if (object.getClock() < ws.getClock()) { DataObject clone = cloneDataObject(ws.getHead(), object, ws.getClock()); tkey = clone.getKey(); meta.setTarget(tkey); if (parent == null) { throw new CoreServiceException("An object should have a parent"); } parent.removeElement(element); parent.addElement(new CollectionElement(DataObject.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), clone.getSize(), clone.getMimeType(), clone.getKey())); em.merge(parent); registry.update(parent.getKey()); object = clone; } object.addMetadata(new MetadataElement(name, key)); em.merge(object); break; case Link.OBJECT_TYPE: Link link = em.find(Link.class, tidentifier.getId()); if (link == null) { ctx.setRollbackOnly(); throw new CoreServiceException( "unable to load link with id [" + tidentifier.getId() + "] from storage"); } link.setKey(tkey); for (MetadataElement mde : link.getMetadatas()) { if (mde.getName().equals(name)) { ctx.setRollbackOnly(); throw new CoreServiceException("a metadata object with name [" + name + "] already exists for link at path [" + npath.build() + "]"); } } if (link.getClock() < ws.getClock()) { Link clone = cloneLink(ws.getHead(), link, ws.getClock()); tkey = clone.getKey(); meta.setTarget(tkey); if (parent == null) { throw new CoreServiceException("A link should have a parent"); } parent.removeElement(element); parent.addElement(new CollectionElement(Link.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, clone.getKey())); em.merge(parent); registry.update(parent.getKey()); link = clone; } link.addMetadata(new MetadataElement(name, key)); em.merge(link); break; } em.merge(meta); indexing.index(tkey); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias()) .addArgument("key", key).addArgument("tkey", tkey).addArgument("path", npath.build()) .addArgument("name", name); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, MetadataObject.OBJECT_TYPE, "create"), argsBuilder.build()); return meta; } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException | IdentifierAlreadyRegisteredException | AuthorisationServiceException | MembershipServiceException | BinaryStoreServiceException | DataNotFoundException | CloneException | IndexingServiceException | OrtolangException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error occurred during metadata creation", e); throw new CoreServiceException( "unable to create metadata into workspace [" + wskey + "] for path [" + path + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public MetadataObject updateMetadataObject(String wskey, String path, String name, String hash, String filename, boolean purgeChildren, String format) throws CoreServiceException, InvalidPathException, MetadataFormatException, PathNotFoundException, WorkspaceReadOnlyException { LOGGER.log(Level.FINE, "updating metadata content into workspace [" + wskey + "] for path [" + path + "] and name [" + name + "]"); try {// ww w . java 2s .c o m PathBuilder npath = PathBuilder.fromPath(path); PathBuilder ppath = npath.clone().parent(); String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException("unable to update metadata object in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "update"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'update' permission on the head collection of this workspace"); String current = resolveWorkspacePath(wskey, Workspace.HEAD, npath.build()); OrtolangObjectIdentifier ctidentifier = registry.lookup(current); if (!ctidentifier.getType().equals(Link.OBJECT_TYPE) && !ctidentifier.getType().equals(Collection.OBJECT_TYPE) && !ctidentifier.getType().equals(DataObject.OBJECT_TYPE)) { throw new CoreServiceException("metadata target can only be a Link, a DataObject or a Collection."); } MetadataElement cmdelement = null; switch (ctidentifier.getType()) { case Collection.OBJECT_TYPE: Collection collection = em.find(Collection.class, ctidentifier.getId()); if (collection == null) { throw new CoreServiceException( "unable to load collection with id [" + ctidentifier.getId() + "] from storage"); } if (collection.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for collection at path [" + npath.build() + "]"); } cmdelement = collection.findMetadataByName(name); break; case DataObject.OBJECT_TYPE: DataObject object = em.find(DataObject.class, ctidentifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load object with id [" + ctidentifier.getId() + "] from storage"); } if (object.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for object at path [" + npath.build() + "]"); } cmdelement = object.findMetadataByName(name); break; case Link.OBJECT_TYPE: Link link = em.find(Link.class, ctidentifier.getId()); if (link == null) { throw new CoreServiceException( "unable to load link with id [" + ctidentifier.getId() + "] from storage"); } if (link.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for link at path [" + npath.build() + "]"); } cmdelement = link.findMetadataByName(name); break; } if (cmdelement == null) { throw new CoreServiceException("unable to find current metadata target into workspace [" + wskey + "] for path [" + npath.build() + "] and name [" + name + "]"); } OrtolangObjectIdentifier cidentifier = registry.lookup(cmdelement.getKey()); checkObjectType(cidentifier, MetadataObject.OBJECT_TYPE); MetadataObject cmeta = em.find(MetadataObject.class, cidentifier.getId()); if (cmeta == null) { throw new CoreServiceException( "unable to load metadata with id [" + cidentifier.getId() + "] from storage"); } if (!cmeta.getStream().equals(hash)) { String tkey = ws.getHead(); Collection parent = null; CollectionElement element = null; if (!npath.isRoot()) { parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build()); element = parent.findElementByName(npath.part()); if (element == null) { throw new PathNotFoundException(npath.build()); } LOGGER.log(Level.FINEST, "collection element found for name " + npath.part()); tkey = element.getKey(); } OrtolangObjectIdentifier tidentifier = registry.lookup(tkey); if (!tidentifier.getType().equals(Link.OBJECT_TYPE) && !tidentifier.getType().equals(Collection.OBJECT_TYPE) && !tidentifier.getType().equals(DataObject.OBJECT_TYPE)) { throw new CoreServiceException( "metadata target can only be a Link, a DataObject or a Collection."); } MetadataElement mdelement = null; Collection collection = null; switch (tidentifier.getType()) { case Collection.OBJECT_TYPE: collection = em.find(Collection.class, tidentifier.getId()); if (collection == null) { throw new CoreServiceException( "unable to load collection with id [" + tidentifier.getId() + "] from storage"); } collection.setKey(tkey); if (collection.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for collection at path [" + npath.build() + "]"); } if (collection.getClock() < ws.getClock()) { Collection clone = cloneCollection(ws.getHead(), collection, ws.getClock()); tkey = clone.getKey(); if (parent != null) { parent.removeElement(element); parent.addElement(new CollectionElement(Collection.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Collection.MIME_TYPE, clone.getKey())); } collection = clone; } mdelement = collection.findMetadataByName(name); break; case DataObject.OBJECT_TYPE: DataObject object = em.find(DataObject.class, tidentifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load object with id [" + tidentifier.getId() + "] from storage"); } object.setKey(tkey); if (object.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for object at path [" + npath.build() + "]"); } if (object.getClock() < ws.getClock()) { DataObject clone = cloneDataObject(ws.getHead(), object, ws.getClock()); tkey = clone.getKey(); if (parent == null) { throw new CoreServiceException("An object should have a parent"); } parent.removeElement(element); parent.addElement(new CollectionElement(DataObject.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), clone.getSize(), clone.getMimeType(), clone.getKey())); object = clone; } mdelement = object.findMetadataByName(name); break; case Link.OBJECT_TYPE: Link link = em.find(Link.class, tidentifier.getId()); if (link == null) { throw new CoreServiceException( "unable to load link with id [" + tidentifier.getId() + "] from storage"); } link.setKey(tkey); if (link.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for link at path [" + npath.build() + "]"); } if (link.getClock() < ws.getClock()) { Link clone = cloneLink(ws.getHead(), link, ws.getClock()); tkey = clone.getKey(); if (parent == null) { throw new CoreServiceException("A link should have a parent"); } parent.removeElement(element); parent.addElement(new CollectionElement(Link.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, clone.getKey())); link = clone; } mdelement = link.findMetadataByName(name); break; } if (mdelement == null) { throw new CoreServiceException("unable to find metadata object into workspace [" + wskey + "] for path [" + npath.build() + "] and name [" + name + "]"); } OrtolangObjectIdentifier identifier = registry.lookup(mdelement.getKey()); checkObjectType(identifier, MetadataObject.OBJECT_TYPE); MetadataObject meta = em.find(MetadataObject.class, identifier.getId()); if (meta == null) { throw new CoreServiceException( "unable to load metadata with id [" + identifier.getId() + "] from storage"); } meta.setKey(mdelement.getKey()); if (hash != null && hash.length() > 0) { if (filename != null) { meta.setContentType(binarystore.type(hash, filename)); } else { meta.setContentType(binarystore.type(hash)); } if (format != null) { meta.setFormat(format); } MetadataFormat metadataFormat = findMetadataFormatById(meta.getFormat()); if (metadataFormat == null) { LOGGER.log(Level.SEVERE, "Unable to find a metadata format for name: " + name); throw new CoreServiceException("unknown metadata format for name: " + name); } if (metadataFormat.isValidationNeeded()) { validateMetadata(hash, metadataFormat); } meta.setSize(binarystore.size(hash)); meta.setStream(hash); meta.setTarget(tkey); } else { throw new CoreServiceException( "unable to update a metadata with an empty content (hash is null)"); } em.merge(meta); registry.update(mdelement.getKey()); indexing.index(tkey); if (collection != null && purgeChildren) { LOGGER.log(Level.FINE, "Purging children metadata"); purgeChildrenMetadata(collection, wskey, path, name); } ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias()) .addArgument("key", mdelement.getKey()).addArgument("tkey", tkey) .addArgument("path", npath.build()).addArgument("name", name); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType( CoreService.SERVICE_NAME, MetadataObject.OBJECT_TYPE, "update"), argsBuilder.build()); return meta; } else { LOGGER.log(Level.FINEST, "no changes detected with current metadata object, nothing to do"); return cmeta; } } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException | AuthorisationServiceException | MembershipServiceException | BinaryStoreServiceException | DataNotFoundException | CloneException | IndexingServiceException | OrtolangException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error occurred during metadata creation", e); throw new CoreServiceException("unable to create metadata into workspace [" + wskey + "] for path [" + path + "] and name [" + name + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void deleteMetadataObject(String wskey, String path, String name, boolean recursive) throws CoreServiceException, InvalidPathException, WorkspaceReadOnlyException, PathNotFoundException { LOGGER.log(Level.FINE, "deleting metadataobject into workspace [" + wskey + "] for path [" + path + "] with name [" + name + "]"); try {/*from www . jav a 2s . c o m*/ PathBuilder npath = PathBuilder.fromPath(path); PathBuilder ppath = npath.clone().parent(); String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkAuthentified(subjects); LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified"); OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey); checkObjectType(wsidentifier, Workspace.OBJECT_TYPE); LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists"); Workspace ws = em.find(Workspace.class, wsidentifier.getId()); if (ws == null) { throw new CoreServiceException( "unable to load workspace with id [" + wsidentifier.getId() + "] from storage"); } if (applyReadOnly(caller, subjects, ws)) { throw new WorkspaceReadOnlyException("unable to delete meta data object in workspace with key [" + wskey + "] because it is read only"); } ws.setKey(wskey); LOGGER.log(Level.FINEST, "workspace loaded"); authorisation.checkPermission(ws.getHead(), subjects, "delete"); LOGGER.log(Level.FINEST, "user [" + caller + "] has 'create' permission on the head collection of this workspace"); String current = resolveWorkspacePath(wskey, Workspace.HEAD, npath.build()); MetadataElement cmdelement = loadMetadataElement(name, current); if (cmdelement == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for at path [" + npath.build() + "]"); } OrtolangObjectIdentifier cidentifier = registry.lookup(cmdelement.getKey()); checkObjectType(cidentifier, MetadataObject.OBJECT_TYPE); MetadataObject cmeta = em.find(MetadataObject.class, cidentifier.getId()); if (cmeta == null) { throw new CoreServiceException( "unable to load metadata with id [" + cidentifier.getId() + "] from storage"); } Collection parent = null; CollectionElement element = null; String tkey; if (npath.isRoot()) { tkey = ws.getHead(); } else { parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock()); LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build()); element = parent.findElementByName(npath.part()); if (element == null) { throw new PathNotFoundException(npath.build()); } LOGGER.log(Level.FINEST, "collection element found for name " + npath.part()); tkey = element.getKey(); } OrtolangObjectIdentifier tidentifier = registry.lookup(tkey); if (!tidentifier.getType().equals(Link.OBJECT_TYPE) && !tidentifier.getType().equals(Collection.OBJECT_TYPE) && !tidentifier.getType().equals(DataObject.OBJECT_TYPE)) { throw new CoreServiceException("metadata target can only be a Link, a DataObject or a Collection."); } MetadataElement mdelement; switch (tidentifier.getType()) { case Collection.OBJECT_TYPE: Collection collection = em.find(Collection.class, tidentifier.getId()); if (collection == null) { throw new CoreServiceException( "unable to load collection with id [" + tidentifier.getId() + "] from storage"); } collection.setKey(tkey); if (collection.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for collection at path [" + npath.build() + "]"); } if (collection.getClock() < ws.getClock()) { Collection clone = cloneCollection(ws.getHead(), collection, ws.getClock()); tkey = clone.getKey(); if (parent != null) { parent.removeElement(element); parent.addElement(new CollectionElement(Collection.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Collection.MIME_TYPE, clone.getKey())); } collection = clone; } mdelement = collection.findMetadataByName(name); if (recursive) { LOGGER.log(Level.FINE, "Removing children metadata"); purgeChildrenMetadata(collection, wskey, path, name); } collection.removeMetadata(mdelement); em.merge(collection); break; case DataObject.OBJECT_TYPE: DataObject object = em.find(DataObject.class, tidentifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load object with id [" + tidentifier.getId() + "] from storage"); } object.setKey(tkey); if (object.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for object at path [" + npath.build() + "]"); } if (object.getClock() < ws.getClock()) { DataObject clone = cloneDataObject(ws.getHead(), object, ws.getClock()); tkey = clone.getKey(); if (parent == null) { throw new CoreServiceException("An object should have a parent"); } parent.removeElement(element); parent.addElement(new CollectionElement(DataObject.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), clone.getSize(), clone.getMimeType(), clone.getKey())); object = clone; } mdelement = object.findMetadataByName(name); object.removeMetadata(mdelement); em.merge(object); break; case Link.OBJECT_TYPE: Link link = em.find(Link.class, tidentifier.getId()); if (link == null) { throw new CoreServiceException( "unable to load link with id [" + tidentifier.getId() + "] from storage"); } link.setKey(tkey); if (link.findMetadataByName(name) == null) { throw new CoreServiceException("a metadata object with name [" + name + "] does not exists for link at path [" + npath.build() + "]"); } if (link.getClock() < ws.getClock()) { Link clone = cloneLink(ws.getHead(), link, ws.getClock()); tkey = clone.getKey(); if (parent == null) { throw new CoreServiceException("A link should have a parent"); } parent.removeElement(element); parent.addElement(new CollectionElement(Link.OBJECT_TYPE, clone.getName(), System.currentTimeMillis(), 0, Link.MIME_TYPE, clone.getKey())); link = clone; } mdelement = link.findMetadataByName(name); link.removeMetadata(mdelement); em.merge(link); break; default: throw new CoreServiceException( "Metadata target should be a Metadata Source not a " + tidentifier.getType()); } if (mdelement == null) { throw new CoreServiceException("unable to find metadata object into workspace [" + wskey + "] for path [" + npath.build() + "] and name [" + name + "]"); } registry.delete(mdelement.getKey()); indexing.remove(mdelement.getKey()); indexing.index(tkey); ws.setChanged(true); em.merge(ws); registry.update(ws.getKey()); LOGGER.log(Level.FINEST, "workspace set changed"); ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias()) .addArgument("key", mdelement.getKey()).addArgument("tkey", tkey) .addArgument("path", npath.build()).addArgument("name", name); notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE, OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, MetadataObject.OBJECT_TYPE, "delete"), argsBuilder.build()); } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException | AuthorisationServiceException | MembershipServiceException | CloneException | IndexingServiceException | OrtolangException e) { ctx.setRollbackOnly(); LOGGER.log(Level.SEVERE, "unexpected error occurred during metadata deletion", e); throw new CoreServiceException( "unable to delete metadata into workspace [" + wskey + "] for path [" + path + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) private void deleteCollectionContent(Collection collection, int clock) throws CoreServiceException, RegistryServiceException, KeyNotFoundException, KeyLockedException, IndexingServiceException { LOGGER.log(Level.FINE, "delete content for collection with id [" + collection.getId() + "]"); for (CollectionElement element : collection.getElements()) { switch (element.getType()) { case Collection.OBJECT_TYPE: { OrtolangObjectIdentifier identifier = registry.lookup(element.getKey()); checkObjectType(identifier, Collection.OBJECT_TYPE); Collection coll = em.find(Collection.class, identifier.getId()); if (coll == null) { throw new CoreServiceException( "unable to load collection with id [" + identifier.getId() + "] from storage"); }//from ww w. j a v a 2 s .co m if (coll.getClock() == clock) { deleteCollectionContent(coll, clock); LOGGER.log(Level.FINEST, "collection clock [" + coll.getClock() + "] is the same, key can be deleted and unindexed"); for (MetadataElement mde : coll.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(element.getKey()); indexing.remove(element.getKey()); } break; } case DataObject.OBJECT_TYPE: { OrtolangObjectIdentifier identifier = registry.lookup(element.getKey()); checkObjectType(identifier, DataObject.OBJECT_TYPE); DataObject object = em.find(DataObject.class, identifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load object with id [" + identifier.getId() + "] from storage"); } if (object.getClock() == clock) { LOGGER.log(Level.FINEST, "object clock [" + object.getClock() + "] is the same, key can be deleted and unindexed"); for (MetadataElement mde : object.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(element.getKey()); indexing.remove(element.getKey()); } break; } case Link.OBJECT_TYPE: { OrtolangObjectIdentifier identifier = registry.lookup(element.getKey()); checkObjectType(identifier, Link.OBJECT_TYPE); Link link = em.find(Link.class, identifier.getId()); if (link == null) { throw new CoreServiceException( "unable to load link with id [" + identifier.getId() + "] from storage"); } if (link.getClock() == clock) { LOGGER.log(Level.FINEST, "link clock [" + link.getClock() + "] is the same, key can be deleted and unindexed"); for (MetadataElement mde : link.getMetadatas()) { registry.delete(mde.getKey()); } registry.delete(element.getKey()); indexing.remove(element.getKey()); } break; } } } }
From source file:ffx.potential.nonbonded.ParticleMeshEwald.java
/** * The least-squares predictor with induced dipole information from 8-10 * previous steps reduces the number SCF iterations by ~50%. *///from w w w . j a v a 2 s . com private void leastSquaresPredictor() { if (predictorCount < 2) { return; } try { /** * The Jacobian and target do not change during the LS optimization, * so it's most efficient to update them once before the * Least-Squares optimizer starts. */ leastSquaresPredictor.updateJacobianAndTarget(); int maxEvals = 100; fill(leastSquaresPredictor.initialSolution, 0.0); leastSquaresPredictor.initialSolution[0] = 1.0; PointVectorValuePair optimum = leastSquaresOptimizer.optimize(maxEvals, leastSquaresPredictor, leastSquaresPredictor.calculateTarget(), leastSquaresPredictor.weights, leastSquaresPredictor.initialSolution); double[] optimalValues = optimum.getPoint(); if (logger.isLoggable(Level.FINEST)) { logger.finest(String.format("\n LS RMS: %10.6f", leastSquaresOptimizer.getRMS())); logger.finest(String.format(" LS Iterations: %10d", leastSquaresOptimizer.getEvaluations())); logger.finest( String.format(" Jacobian Evals: %10d", leastSquaresOptimizer.getJacobianEvaluations())); logger.finest(String.format(" Chi Square: %10.6f", leastSquaresOptimizer.getChiSquare())); logger.finest(String.format(" LS Coefficients")); for (int i = 0; i < predictorOrder - 1; i++) { logger.finest(String.format(" %2d %10.6f", i + 1, optimalValues[i])); } } int mode; switch (lambdaMode) { case OFF: case CONDENSED: mode = 0; break; case CONDENSED_NO_LIGAND: mode = 1; break; case VAPOR: mode = 2; break; default: mode = 0; } /** * Initialize a pointer into predictor induced dipole array. */ int index = predictorStartIndex; /** * Apply the LS coefficients in order to provide an initial guess at * the converged induced dipoles. */ for (int k = 0; k < predictorOrder - 1; k++) { /** * Set the current coefficient. */ double c = optimalValues[k]; for (int i = 0; i < nAtoms; i++) { for (int j = 0; j < 3; j++) { inducedDipole[0][i][j] += c * predictorInducedDipole[mode][index][i][j]; inducedDipoleCR[0][i][j] += c * predictorInducedDipoleCR[mode][index][i][j]; } } index++; if (index >= predictorOrder) { index = 0; } } } catch (Exception e) { logger.log(Level.WARNING, " Exception computing predictor coefficients", e); } }