Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions components/blitz/src/omero/cmd/graphs/Chgrp2I.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2014-2017 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -29,6 +29,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -77,6 +78,7 @@ public class Chgrp2I extends Chgrp2 implements IRequest, WrappableRequest<Chgrp2
private final Set<Class<? extends IObject>> targetClasses;
private GraphPolicy graphPolicy; /* not final because of adjustGraphPolicy */
private final SetMultimap<String, String> unnullable;
private final ApplicationContext applicationContext;

private List<Function<GraphPolicy, GraphPolicy>> graphPolicyAdjusters = new ArrayList<Function<GraphPolicy, GraphPolicy>>();
private Helper helper;
Expand All @@ -100,17 +102,19 @@ public class Chgrp2I extends Chgrp2 implements IRequest, WrappableRequest<Chgrp2
* @param targetClasses legal target object classes for chgrp
* @param graphPolicy the graph policy to apply for chgrp
* @param unnullable properties that, while nullable, may not be nulled by a graph traversal operation
* @param applicationContext the OMERO application context from Spring
*/
public Chgrp2I(ACLVoter aclVoter, Roles securityRoles, SystemTypes systemTypes, GraphPathBean graphPathBean,
Deletion deletionInstance, Set<Class<? extends IObject>> targetClasses, GraphPolicy graphPolicy,
SetMultimap<String, String> unnullable) {
SetMultimap<String, String> unnullable, ApplicationContext applicationContext) {
this.aclVoter = aclVoter;
this.systemTypes = systemTypes;
this.graphPathBean = graphPathBean;
this.deletionInstance = deletionInstance;
this.targetClasses = targetClasses;
this.graphPolicy = graphPolicy;
this.unnullable = unnullable;
this.applicationContext = applicationContext;
}

@Override
Expand Down Expand Up @@ -282,11 +286,18 @@ public InternalProcessor() {
super(helper.getSession());
}

@Override
public void deleteInstances(String className, Collection<Long> ids) throws GraphException {
super.deleteInstances(className, ids);
graphHelper.publishEventLog(applicationContext, "DELETE", className, ids);
}

@Override
public void processInstances(String className, Collection<Long> ids) throws GraphException {
final String update = "UPDATE " + className + " SET details.group = :group WHERE id IN (:ids)";
final int count =
session.createQuery(update).setParameter("group", group).setParameterList("ids", ids).executeUpdate();
graphHelper.publishEventLog(applicationContext, "UPDATE", className, ids);
if (count != ids.size()) {
LOGGER.warn("not all the objects of type " + className + " could be processed");
}
Expand Down
15 changes: 13 additions & 2 deletions components/blitz/src/omero/cmd/graphs/Chmod2I.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2014-2017 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -30,6 +30,7 @@
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.google.common.base.Function;
import com.google.common.collect.HashMultimap;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class Chmod2I extends Chmod2 implements IRequest, WrappableRequest<Chmod2
private final Set<Class<? extends IObject>> targetClasses;
private GraphPolicy graphPolicy; /* not final because of adjustGraphPolicy */
private final SetMultimap<String, String> unnullable;
private final ApplicationContext applicationContext;

private long perm1;
private List<Function<GraphPolicy, GraphPolicy>> graphPolicyAdjusters = new ArrayList<Function<GraphPolicy, GraphPolicy>>();
Expand All @@ -110,10 +112,11 @@ public class Chmod2I extends Chmod2 implements IRequest, WrappableRequest<Chmod2
* @param targetClasses legal target object classes for chmod
* @param graphPolicy the graph policy to apply for chmod
* @param unnullable properties that, while nullable, may not be nulled by a graph traversal operation
* @param applicationContext the OMERO application context from Spring
*/
public Chmod2I(ACLVoter aclVoter, Roles securityRoles, SystemTypes systemTypes, GraphPathBean graphPathBean,
Deletion deletionInstance, Set<Class<? extends IObject>> targetClasses, GraphPolicy graphPolicy,
SetMultimap<String, String> unnullable) {
SetMultimap<String, String> unnullable, ApplicationContext applicationContext) {
this.aclVoter = aclVoter;
this.securityRoles = securityRoles;
this.systemTypes = systemTypes;
Expand All @@ -122,6 +125,7 @@ public Chmod2I(ACLVoter aclVoter, Roles securityRoles, SystemTypes systemTypes,
this.targetClasses = targetClasses;
this.graphPolicy = graphPolicy;
this.unnullable = unnullable;
this.applicationContext = applicationContext;
}

@Override
Expand Down Expand Up @@ -326,11 +330,18 @@ public InternalProcessor() {
super(helper.getSession());
}

@Override
public void deleteInstances(String className, Collection<Long> ids) throws GraphException {
super.deleteInstances(className, ids);
graphHelper.publishEventLog(applicationContext, "DELETE", className, ids);
}

@Override
public void processInstances(String className, Collection<Long> ids) throws GraphException {
final String update = "UPDATE " + className + " SET details.permissions.perm1 = :permissions WHERE id IN (:ids)";
final int count =
session.createQuery(update).setParameter("permissions", perm1).setParameterList("ids", ids).executeUpdate();
graphHelper.publishEventLog(applicationContext, "UPDATE", className, ids);
if (count != ids.size()) {
LOGGER.warn("not all the objects of type " + className + " could be processed");
}
Expand Down
15 changes: 13 additions & 2 deletions components/blitz/src/omero/cmd/graphs/Chown2I.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2014-2017 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -33,6 +33,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.google.common.base.Function;
import com.google.common.collect.HashMultimap;
Expand Down Expand Up @@ -94,6 +95,7 @@ public class Chown2I extends Chown2 implements IRequest, WrappableRequest<Chown2
private final Set<Class<? extends IObject>> targetClasses;
private GraphPolicy graphPolicy; /* not final because of adjustGraphPolicy */
private final SetMultimap<String, String> unnullable;
private final ApplicationContext applicationContext;

private List<Function<GraphPolicy, GraphPolicy>> graphPolicyAdjusters = new ArrayList<Function<GraphPolicy, GraphPolicy>>();
private Helper helper;
Expand All @@ -119,17 +121,19 @@ public class Chown2I extends Chown2 implements IRequest, WrappableRequest<Chown2
* @param targetClasses legal target object classes for chown
* @param graphPolicy the graph policy to apply for chown
* @param unnullable properties that, while nullable, may not be nulled by a graph traversal operation
* @param applicationContext the OMERO application context from Spring
*/
public Chown2I(ACLVoter aclVoter, Roles securityRoles, SystemTypes systemTypes, GraphPathBean graphPathBean,
Deletion deletionInstance, Set<Class<? extends IObject>> targetClasses, GraphPolicy graphPolicy,
SetMultimap<String, String> unnullable) {
SetMultimap<String, String> unnullable, ApplicationContext applicationContext) {
this.aclVoter = aclVoter;
this.systemTypes = systemTypes;
this.graphPathBean = graphPathBean;
this.deletionInstance = deletionInstance;
this.targetClasses = targetClasses;
this.graphPolicy = graphPolicy;
this.unnullable = unnullable;
this.applicationContext = applicationContext;
}

@Override
Expand Down Expand Up @@ -457,11 +461,18 @@ public InternalProcessor() {
super(helper.getSession());
}

@Override
public void deleteInstances(String className, Collection<Long> ids) throws GraphException {
super.deleteInstances(className, ids);
graphHelper.publishEventLog(applicationContext, "DELETE", className, ids);
}

@Override
public void processInstances(String className, Collection<Long> ids) throws GraphException {
final String update = "UPDATE " + className + " SET details.owner = :user WHERE id IN (:ids)";
final int count =
session.createQuery(update).setParameter("user", userTo).setParameterList("ids", ids).executeUpdate();
graphHelper.publishEventLog(applicationContext, "UPDATE", className, ids);
if (count != ids.size()) {
LOGGER.warn("not all the objects of type " + className + " could be processed");
}
Expand Down
15 changes: 12 additions & 3 deletions components/blitz/src/omero/cmd/graphs/Delete2I.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2014-2017 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -29,11 +29,11 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;

import ome.model.IObject;
Expand Down Expand Up @@ -74,6 +74,7 @@ public class Delete2I extends Delete2 implements IRequest, WrappableRequest<Dele
private final Deletion deletionInstance;
private GraphPolicy graphPolicy; /* not final because of adjustGraphPolicy */
private final SetMultimap<String, String> unnullable;
private final ApplicationContext applicationContext;

private List<Function<GraphPolicy, GraphPolicy>> graphPolicyAdjusters = new ArrayList<Function<GraphPolicy, GraphPolicy>>();
private Helper helper;
Expand All @@ -96,17 +97,19 @@ public class Delete2I extends Delete2 implements IRequest, WrappableRequest<Dele
* @param targetClasses legal target object classes for delete
* @param graphPolicy the graph policy to apply for delete
* @param unnullable properties that, while nullable, may not be nulled by a graph traversal operation
* @param applicationContext the OMERO application context from Spring
*/
public Delete2I(ACLVoter aclVoter, Roles securityRoles, SystemTypes systemTypes, GraphPathBean graphPathBean,
Deletion deletionInstance, Set<Class<? extends IObject>> targetClasses, GraphPolicy graphPolicy,
SetMultimap<String, String> unnullable) {
SetMultimap<String, String> unnullable, ApplicationContext applicationContext) {
this.aclVoter = aclVoter;
this.systemTypes = systemTypes;
this.graphPathBean = graphPathBean;
this.deletionInstance = deletionInstance;
this.targetClasses = targetClasses;
this.graphPolicy = graphPolicy;
this.unnullable = unnullable;
this.applicationContext = applicationContext;
}

@Override
Expand Down Expand Up @@ -257,6 +260,12 @@ public InternalProcessor() {
super(helper.getSession());
}

@Override
public void deleteInstances(String className, Collection<Long> ids) throws GraphException {
super.deleteInstances(className, ids);
graphHelper.publishEventLog(applicationContext, "DELETE", className, ids);
}

@Override
public void processInstances(String className, Collection<Long> ids) throws GraphException {
deleteInstances(className, ids);
Expand Down
8 changes: 4 additions & 4 deletions components/blitz/src/omero/cmd/graphs/DuplicateI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2014-2017 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -22,7 +22,6 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -33,13 +32,13 @@

import org.apache.commons.beanutils.NestedNullException;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.proxy.HibernateProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.google.common.base.Function;
import com.google.common.base.Functions;
Expand Down Expand Up @@ -129,10 +128,11 @@ private static enum Inclusion {
* @param targetClasses legal target object classes for duplicate
* @param graphPolicy the graph policy to apply for duplicate
* @param unnullable properties that, while nullable, may not be nulled by a graph traversal operation
* @param applicationContext the OMERO application context from Spring
*/
public DuplicateI(ACLVoter aclVoter, Roles securityRoles, SystemTypes systemTypes, GraphPathBean graphPathBean,
Deletion deletionInstance, Set<Class<? extends IObject>> targetClasses, GraphPolicy graphPolicy,
SetMultimap<String, String> unnullable) {
SetMultimap<String, String> unnullable, ApplicationContext applicationContext) {
this.aclVoter = aclVoter;
this.systemTypes = systemTypes;
this.graphPathBean = graphPathBean;
Expand Down
23 changes: 22 additions & 1 deletion components/blitz/src/omero/cmd/graphs/GraphHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2014-2017 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -28,17 +28,21 @@
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.context.ApplicationContext;

import com.google.common.base.Function;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;

import ome.conditions.InternalException;
import ome.model.IObject;
import ome.security.ACLVoter;
import ome.security.SystemTypes;
import ome.services.graphs.GraphPathBean;
import ome.services.graphs.GraphPolicy;
import ome.services.graphs.GraphTraversal;
import ome.services.messages.EventLogMessage;
import omero.cmd.ERR;
import omero.cmd.Helper;

Expand Down Expand Up @@ -209,4 +213,21 @@ public Set<String> getTopLevelNames(Iterable<Class<? extends IObject>> modelClas
}
return classNames;
}

/**
* Publish database changes to the event log.
* @param context the context for publishing the application event
* @param action the name of the change action
* @param className the class of objects that were changed
* @param ids the IDs of the objects that were changed
*/
public void publishEventLog(ApplicationContext context, String action, String className, Collection<Long> ids) {
final Class<? extends IObject> actualClass;
try {
actualClass = Class.forName(className).asSubclass(IObject.class);
} catch (ClassNotFoundException cnfe) {
throw new InternalException("reference to unknown model class " + className + ": " + cnfe);
}
context.publishEvent(new EventLogMessage(this, action, actualClass, ImmutableList.copyOf(ids)));
}
}
Loading