mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
DS-3004: Added to group name as a column to the group entity and use to to find groups by name instead of searching in the metdata
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.eperson;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.DSpaceObjectLegacySupport;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
@@ -48,6 +49,9 @@ public class Group extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
@Column
|
||||
private Boolean permanent = false;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
/** lists of epeople and groups in the group */
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
@@ -197,15 +201,21 @@ public class Group extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return getGroupService().getName(this);
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Change the name of this Group. */
|
||||
void setName(Context context, String name) throws SQLException
|
||||
{
|
||||
if(!StringUtils.equals(this.name, name)) {
|
||||
this.name = name;
|
||||
groupsChanged = true;
|
||||
|
||||
//Also update the name in the metadata
|
||||
getGroupService().setMetadataSingleValue(context, this,
|
||||
MetadataSchema.DC_SCHEMA, "title", null, null, name);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGroupsChanged() {
|
||||
return groupsChanged;
|
||||
|
@@ -26,14 +26,13 @@ import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
import org.dspace.eperson.service.EPersonService;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.dspace.event.Event;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Service implementation for the Group object.
|
||||
* This class is responsible for all business logic calls for the Group object and is autowired by spring.
|
||||
@@ -247,7 +246,7 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
|
||||
return null;
|
||||
}
|
||||
|
||||
return groupDAO.findByMetadataField(context, name, metadataFieldService.findByElement(context, MetadataSchema.DC_SCHEMA, "title", null));
|
||||
return groupDAO.findByName(context, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -41,4 +41,6 @@ public interface GroupDAO extends DSpaceObjectDAO<Group>, DSpaceObjectLegacySupp
|
||||
List<Group> getEmptyGroups(Context context) throws SQLException;
|
||||
|
||||
int countRows(Context context) throws SQLException;
|
||||
|
||||
Group findByName(Context context, String name) throws SQLException;
|
||||
}
|
||||
|
@@ -79,6 +79,16 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
||||
return list(query);
|
||||
}
|
||||
|
||||
public Group findByName(final Context context, final String name) throws SQLException {
|
||||
Query query = createQuery(context,
|
||||
"select g from Group g " +
|
||||
"where g.name = :name ");
|
||||
|
||||
query.setParameter("name", name);
|
||||
|
||||
return uniqueResult(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> search(Context context, String query, List<MetadataField> queryFields, int offset, int limit) throws SQLException {
|
||||
String groupTableName = "g";
|
||||
@@ -167,4 +177,5 @@ public class GroupDAOImpl extends AbstractHibernateDSODAO<Group> implements Grou
|
||||
public int countRows(Context context) throws SQLException {
|
||||
return count(createQuery(context, "SELECT count(*) FROM Group"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user