diff --git a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java index d3839818f83..79a2a9498c9 100644 --- a/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java @@ -93,6 +93,11 @@ public ClarinLicense findByName(Context context, String name) throws SQLExceptio return clarinLicenseDAO.findByName(context, name); } + @Override + public List findByNameLike(Context context, String name) throws SQLException { + return clarinLicenseDAO.findByNameLike(context, name); + } + @Override public void addLicenseMetadataToItem(Context context, ClarinLicense clarinLicense, Item item) throws SQLException { if (Objects.isNull(clarinLicense) || Objects.isNull(item)) { diff --git a/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java index 67bb310b679..99147af64e6 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java @@ -8,6 +8,7 @@ package org.dspace.content.dao.clarin; import java.sql.SQLException; +import java.util.List; import org.dspace.content.clarin.ClarinLicense; import org.dspace.core.Context; @@ -25,4 +26,6 @@ public interface ClarinLicenseDAO extends GenericDAO { ClarinLicense findByName(Context context, String name) throws SQLException; + List findByNameLike(Context context, String name) throws SQLException; + } diff --git a/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java b/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java index dd8d3711be5..24bbe180307 100644 --- a/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java @@ -8,9 +8,14 @@ package org.dspace.content.dao.impl.clarin; import java.sql.SQLException; +import java.util.List; import javax.persistence.Query; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; import org.dspace.content.clarin.ClarinLicense; +import org.dspace.content.clarin.ClarinLicense_; import org.dspace.content.dao.clarin.ClarinLicenseDAO; import org.dspace.core.AbstractHibernateDAO; import org.dspace.core.Context; @@ -38,4 +43,15 @@ public ClarinLicense findByName(Context context, String name) throws SQLExceptio return singleResult(query); } + + @Override + public List findByNameLike(Context context, String name) throws SQLException { + CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context); + CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, ClarinLicense.class); + Root clarinLicenseRoot = criteriaQuery.from(ClarinLicense.class); + criteriaQuery.select(clarinLicenseRoot); + criteriaQuery.where(criteriaBuilder.like(clarinLicenseRoot.get(ClarinLicense_.name), "%" + name + "%")); + criteriaQuery.orderBy(criteriaBuilder.asc(clarinLicenseRoot.get(ClarinLicense_.name))); + return list(context, criteriaQuery, false, ClarinLicense.class, -1, -1); + } } diff --git a/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java b/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java index 86d256e752e..93fbe88df3c 100644 --- a/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java +++ b/dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java @@ -57,8 +57,26 @@ public interface ClarinLicenseService { */ ClarinLicense find(Context context, int valueId) throws SQLException; + /** + * Find the Clarin License by the full clarin license name. + * + * @param context DSpace context object + * @param name the full clarin license name + * @return Clarin License with searching name. + * @throws SQLException + */ ClarinLicense findByName(Context context, String name) throws SQLException; + /** + * Find the Clarin License by the substring of the clarin license name. + * + * @param context DSpace context object + * @param name substring of the clarin license name + * @return List of clarin licenses which contains searching string in it's name + * @throws SQLException + */ + List findByNameLike(Context context, String name) throws SQLException; + void addLicenseMetadataToItem(Context context, ClarinLicense clarinLicense, Item item) throws SQLException; void clearLicenseMetadataFromItem(Context context, Item item) throws SQLException; diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinLicenseRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinLicenseRestRepository.java index 14c09b3aa3f..39ea789324d 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinLicenseRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinLicenseRestRepository.java @@ -45,6 +45,7 @@ import org.springframework.data.rest.webmvc.ResourceNotFoundException; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; /** * This is the repository responsible to manage Clarin License Rest object @@ -101,6 +102,22 @@ public Page findByName(@Parameter(value = "name", required = return converter.toRestPage(clarinLicenseList, pageable, utils.obtainProjection()); } + @SearchRestMethod(name = "byNameLike") + public Page findByNameLike(@Parameter(value = "name", required = true) String name, + Pageable pageable) { + List clarinLicenseList; + try { + Context context = obtainContext(); + clarinLicenseList = clarinLicenseService.findByNameLike(context, name); + if (CollectionUtils.isEmpty(clarinLicenseList)) { + return null; + } + } catch (SQLException e) { + throw new RuntimeException(e.getMessage(), e); + } + return converter.toRestPage(clarinLicenseList, pageable, utils.obtainProjection()); + } + @Override @PreAuthorize("hasAuthority('ADMIN')") public Page findAll(Context context, Pageable pageable) { diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java index 6ad681ea105..7a84b036b00 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/ClarinLicenseRestRepositoryIT.java @@ -208,6 +208,51 @@ public void findAll() throws Exception { Matchers.containsString("/api/core/clarinlicenses"))); } + /** + * Should find one license by the name. + */ + @Test + public void searchBy() throws Exception { + String authTokenAdmin = getAuthToken(admin.getEmail(), password); + getClient(authTokenAdmin).perform(get("/api/core/clarinlicenses/search/byName") + .param("name", "CL Name1")) + .andExpect(status().isOk()) + .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$._embedded.clarinlicenses", Matchers.hasItem( + ClarinLicenseMatcher.matchClarinLicense(firstCLicense)) + )); + } + + /** + * Should find all licenses by the common substring of it's the name. + */ + @Test + public void searchByLike() throws Exception { + String authTokenAdmin = getAuthToken(admin.getEmail(), password); + getClient(authTokenAdmin).perform(get("/api/core/clarinlicenses/search/byNameLike") + .param("name", "Name")) + .andExpect(status().isOk()) + .andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$._embedded.clarinlicenses", Matchers.hasItem( + ClarinLicenseMatcher.matchClarinLicense(firstCLicense)) + )) + .andExpect(jsonPath("$._embedded.clarinlicenses", Matchers.hasItem( + ClarinLicenseMatcher.matchClarinLicense(secondCLicense)) + )) + .andExpect(jsonPath("$._embedded.clarinlicenses[0].clarinLicenseLabel", Matchers.is( + ClarinLicenseLabelMatcher.matchClarinLicenseLabel( + Objects.requireNonNull(getNonExtendedLicenseLabel(firstCLicense.getLicenseLabels())))) + )) + .andExpect(jsonPath("$._embedded.clarinlicenses[0].extendedClarinLicenseLabels", + Matchers.hasItem( + ClarinLicenseLabelMatcher.matchClarinLicenseLabel( + Objects.requireNonNull(getExtendedLicenseLabels( + firstCLicense.getLicenseLabels()))) + ))) + .andExpect(jsonPath("$._links.self.href", + Matchers.containsString("/api/core/clarinlicenses"))); + } + @Test public void create() throws Exception { ClarinLicenseRest clarinLicenseRest = new ClarinLicenseRest(); diff --git a/scripts/fast-build/config-update.bat b/scripts/fast-build/config-update.bat new file mode 100644 index 00000000000..800fc97205f --- /dev/null +++ b/scripts/fast-build/config-update.bat @@ -0,0 +1,8 @@ +call ..\envs\__basic.bat + +call tomcat\stop.bat + +rem copy all config files +xcopy /e /h /i /q /y %dspace_source%\dspace\config\ %dspace_application%\config\ + +cd %dspace_source%\scripts\fast-build\