@Override public int hashCode() { return new HashCodeBuilder().append(getID()).toHashCode(); }
protected List<String> getCollectionLocations(Context context, Collection target) throws SQLException { List<String> locations = new Vector<String>(); // build list of community ids List<Community> communities = communityService.getAllParents(context, target); // now put those into strings for (Community community : communities) { locations.add("m" + community.getID()); } return locations; }
private void findComms(Community comm, List<Object> parentComms) throws SQLException { if (comm == null) { return; } if (!parentComms.contains(comm.getID())) { parentComms.add(comm.getID()); } List<Community> parentCommunities = comm.getParentCommunities(); Community parent = parentCommunities.size() == 0 ? null : parentCommunities.get(0); findComms(parent, parentComms); }
private List<String> getCollectionLocations(Collection target) throws SQLException { List<String> locations = new Vector<String>(); // build list of community ids Community[] communities = target.getCommunities(); // now put those into strings for (Community community : communities) { locations.add("m" + community.getID()); } return locations; }
/** * Return <code>true</code> if <code>other</code> is the same Community * as this object, <code>false</code> otherwise * * @param other object to compare to * @return <code>true</code> if object passed in represents the same * community as this object */ @Override public boolean equals(Object other) { if (other == null) { return false; } Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(other); if (this.getClass() != objClass) { return false; } final Community otherCommunity = (Community) other; if (!this.getID().equals(otherCommunity.getID())) { return false; } return true; }
@Override public void removeSubcommunity(Context context, Community parentCommunity, Community childCommunity) throws SQLException, AuthorizeException, IOException { // Check authorisation authorizeService.authorizeAction(context, parentCommunity, Constants.REMOVE); ArrayList<String> removedIdentifiers = getIdentifiers(context, childCommunity); String removedHandle = childCommunity.getHandle(); UUID removedId = childCommunity.getID(); rawDelete(context, childCommunity); log.info(LogManager.getHeader(context, "remove_subcommunity", "parent_comm_id=" + parentCommunity.getID() + ",child_comm_id=" + childCommunity .getID())); context.addEvent( new Event(Event.REMOVE, Constants.COMMUNITY, parentCommunity.getID(), Constants.COMMUNITY, removedId, removedHandle, removedIdentifiers)); }
/** * @param context DSpace context * @param myitem the item for which our locations are to be retrieved * @return a list containing the identifiers of the communities and collections * @throws SQLException sql exception */ protected List<String> getItemLocations(Context context, Item myitem) throws SQLException { List<String> locations = new Vector<String>(); // build list of community ids List<Community> communities = itemService.getCommunities(context, myitem); // build list of collection ids List<Collection> collections = myitem.getCollections(); // now put those into strings int i = 0; for (i = 0; i < communities.size(); i++) { locations.add("m" + communities.get(i).getID()); } for (i = 0; i < collections.size(); i++) { locations.add("l" + collections.get(i).getID()); } return locations; }
/** * Get the count of the items in the given container. * * @param dso Dspace Context * @return count * @throws ItemCountException if count error */ @Override public int getCount(DSpaceObject dso) throws ItemCountException { loadCount(); Integer val; if (dso instanceof Collection) { val = collectionsCount.get(String.valueOf(((Collection) dso).getID())); } else if (dso instanceof Community) { val = communitiesCount.get(String.valueOf(((Community) dso).getID())); } else { throw new ItemCountException("We can only count items in Communities or Collections"); } if (val != null) { return val.intValue(); } else { return 0; } }
@Override public void addSubcommunity(Context context, Community parentCommunity, Community childCommunity) throws SQLException, AuthorizeException { // Check authorisation authorizeService.authorizeAction(context, parentCommunity, Constants.ADD); log.info(LogManager.getHeader(context, "add_subcommunity", "parent_comm_id=" + parentCommunity.getID() + ",child_comm_id=" + childCommunity .getID())); if (!parentCommunity.getSubcommunities().contains(childCommunity)) { parentCommunity.addSubCommunity(childCommunity); childCommunity.addParentCommunity(parentCommunity); } context.addEvent(new Event(Event.ADD, Constants.COMMUNITY, parentCommunity.getID(), Constants.COMMUNITY, childCommunity.getID(), parentCommunity.getHandle(), getIdentifiers(context, parentCommunity))); }
/** * @param myitem the item for which our locations are to be retrieved * @return a list containing the identifiers of the communities & collections * @throws SQLException sql exception */ private List<String> getItemLocations(Item myitem) throws SQLException { List<String> locations = new Vector<String>(); // build list of community ids Community[] communities = myitem.getCommunities(); // build list of collection ids Collection[] collections = myitem.getCollections(); // now put those into strings int i = 0; for (i = 0; i < communities.length; i++) { locations.add("m" + communities[i].getID()); } for (i = 0; i < collections.length; i++) { locations.add("l" + collections[i].getID()); } return locations; }
@Override public void updateLastModified(Context context, Community community) { //Also fire a modified event since the community HAS been modified context.addEvent(new Event(Event.MODIFY, Constants.COMMUNITY, community.getID(), null, getIdentifiers(context, community))); }
/** * @param c context * @param parent parent Community * @param child child community * @throws SQLException if database error * @throws AuthorizeException if authorize error * @throws IOException if IO error */ public void defiliate(Context c, Community parent, Community child) throws SQLException, AuthorizeException, IOException { // verify that child is indeed a child of parent List<Community> parentKids = parent.getSubcommunities(); if (!parentKids.contains(child)) { System.out.println("Error, child community not a child of parent community"); System.exit(1); } // OK remove the mappings - but leave the community, which will become // top-level child.removeParentCommunity(parent); parent.removeSubCommunity(child); communityService.update(c, child); communityService.update(c, parent); // complete the pending transaction c.complete(); System.out.println("Defiliation complete. Community: '" + child.getID() + "' is no longer a child of community: '" + parent.getID() + "'"); }
@Override public void addCollection(Context context, Community community, Collection collection) throws SQLException, AuthorizeException { // Check authorisation authorizeService.authorizeAction(context, community, Constants.ADD); log.info(LogManager.getHeader(context, "add_collection", "community_id=" + community.getID() + ",collection_id=" + collection.getID())); if (!community.getCollections().contains(collection)) { community.addCollection(collection); collection.addCommunity(community); } context.addEvent( new Event(Event.ADD, Constants.COMMUNITY, community.getID(), Constants.COLLECTION, collection.getID(), community.getHandle(), getIdentifiers(context, community))); }
@Override public void removeCollection(Context context, Community community, Collection collection) throws SQLException, AuthorizeException, IOException { // Check authorisation authorizeService.authorizeAction(context, community, Constants.REMOVE); ArrayList<String> removedIdentifiers = collectionService.getIdentifiers(context, collection); String removedHandle = collection.getHandle(); UUID removedId = collection.getID(); if (collection.getCommunities().size() == 1) { collectionService.delete(context, collection); } else { community.removeCollection(collection); collection.removeCommunity(community); } log.info(LogManager.getHeader(context, "remove_collection", "community_id=" + community.getID() + ",collection_id=" + collection.getID())); // Remove any mappings context.addEvent(new Event(Event.REMOVE, Constants.COMMUNITY, community.getID(), Constants.COLLECTION, removedId, removedHandle, removedIdentifiers)); }
@Override public void update(Context context, Community community) throws SQLException, AuthorizeException { // Check authorisation canEdit(context, community); log.info(LogManager.getHeader(context, "update_community", "community_id=" + community.getID())); super.update(context, community); communityDAO.save(context, community); if (community.isModified()) { context.addEvent(new Event(Event.MODIFY, Constants.COMMUNITY, community.getID(), null, getIdentifiers(context, community))); community.clearModified(); } if (community.isMetadataModified()) { context.addEvent( new Event(Event.MODIFY_METADATA, Constants.COMMUNITY, community.getID(), community.getDetails(), getIdentifiers(context, community))); community.clearModified(); } community.clearDetails(); }
private UUID mapId(FIELD col, int val) throws SQLException { if (col == FIELD.owningComm) { Community comm = communityService.findByLegacyId(context, val); return comm == null ? null : comm.getID(); } if (col == FIELD.owningColl) { org.dspace.content.Collection coll = collectionService.findByLegacyId(context, val); return coll == null ? null : coll.getID(); } if (col == FIELD.owningItem) { Item item = itemService.findByLegacyId(context, val); checkLastItem(item); return item == null ? null : item.getID(); } if (col == FIELD.epersonid || col == FIELD.actor || col == FIELD.submitter) { EPerson per = epersonService.findByLegacyId(context, val); return per == null ? null : per.getID(); } return null; }
@Override public Group createAdministrators(Context context, Community community) throws SQLException, AuthorizeException { // Check authorisation - Must be an Admin to create more Admins AuthorizeUtil.authorizeManageAdminGroup(context, community); Group admins = community.getAdministrators(); if (admins == null) { //turn off authorization so that Community Admins can create Sub-Community Admins context.turnOffAuthorisationSystem(); admins = groupService.create(context); context.restoreAuthSystemState(); groupService.setName(admins, "COMMUNITY_" + community.getID() + "_ADMIN"); groupService.update(context, admins); } authorizeService.addPolicy(context, community, Constants.ADMIN, admins); // register this as the admin group community.setAdmins(admins); return admins; }
private UUID mapType(int type, int val) throws SQLException { if (type == Constants.COMMUNITY) { Community comm = communityService.findByLegacyId(context, val); return comm == null ? null : comm.getID(); } if (type == Constants.COLLECTION) { org.dspace.content.Collection coll = collectionService.findByLegacyId(context, val); return coll == null ? null : coll.getID(); } if (type == Constants.ITEM) { Item item = itemService.findByLegacyId(context, val); checkLastItem(item); return item == null ? null : item.getID(); } if (type == Constants.BITSTREAM) { Bitstream bit = bitstreamService.findByLegacyId(context, val); UUID uuid = bit == null ? null : bit.getID(); // A bitstream is unlikely to be processed more than once, to clear immediately checkLastBitstream(bit); return uuid; } return null; }
/** * Build a Lucene document for a DSpace Community. * * @param community Community to be indexed * @throws SQLException * @throws IOException */ private void buildDocument(Community community) throws SQLException, IOException { // Create Document SolrInputDocument doc = buildDocument(Constants.COMMUNITY, community.getID(), community.getHandle(), null); // and populate it String name = community.getMetadata("name"); if (name != null) { doc.addField("name", name); } //Do any additional indexing, depends on the plugins List<SolrServiceIndexPlugin> solrServiceIndexPlugins = new DSpace().getServiceManager().getServicesByType(SolrServiceIndexPlugin.class); for (SolrServiceIndexPlugin solrServiceIndexPlugin : solrServiceIndexPlugins) { solrServiceIndexPlugin.additionalIndex(community, doc); } writeDocument(doc); }