Skip to content

Commit e738a32

Browse files
milanmajchrakMilan Majchrákclaude
authored
CLARIN-DSpace v9/Port #1325 (ClarinLicenseLabel PUT/DELETE) to the v9 base (#1376)
Cherry-pick of eebe17d "[Port to dtq-dev] Issue 1343: add PUT and DELETE endpoint methods to ClarinLicenseLabel REST repository (#1325)", adapted for DSpace 9. This port was dropped when CLARIN was merged into the v9 base: dtq-dev-9-base carries every other CLARIN 7.6 migration but not this one. Diffing the migration sets against dtq-dev shows exactly one missing: V7.6_2026.06.01__license_label_constraint.sql which is why importing a dev-5 (CLARIN 7.6) dump onto this branch dies with FlywayValidateException: Detected applied migration not resolved locally: 7.6.2026.06.01. The deploy workflow currently works around that with `dspace database repair`. That masks the gap rather than fixing it -- and would mask the next dropped migration just as quietly -- so fix the cause: bring the port back. The rest of #1325 was missing too (REST repository had no put, no DELETE, no DAO/service methods, no ClarinLicenseLabelNotFoundException). Adapted for v9 (javax -> jakarta; the branch is fully Jakarta EE -- 283 files import jakarta.servlet.http.HttpServletRequest and none import the javax one): - ClarinLicenseDAOImpl javax.persistence.* -> jakarta.persistence.* The only real cherry-pick conflict. Adds Predicate and SetJoin, which the new findByLabel needs. - ClarinLicenseLabelDAOImpl javax.persistence.* -> jakarta.persistence.* This one merged CLEANLY and silently: 9-base had no persistence imports at all, so git had nothing to conflict with, and it would simply not have compiled. - ClarinLicenseLabelNotFoundException javax.ws.rs -> jakarta.ws.rs - ClarinLicenseLabelRestRepository javax.servlet -> jakarta.servlet Import order follows the v9 convention checkstyle enforces: jakarta.* belongs to the third-party group, lexicographically between com.* and org.*. Verified locally: dspace-api compile, dspace-server-webapp compile and test-compile, checkstyle on both -- all clean. Co-authored-by: Milan Majchrák <minptai7@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5ed36b3 commit e738a32

16 files changed

Lines changed: 470 additions & 46 deletions

File tree

dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseLabelServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public List<ClarinLicenseLabel> findAll(Context context) throws SQLException, Au
7676
return clarinLicenseLabelDAO.findAll(context, ClarinLicenseLabel.class);
7777
}
7878

79+
@Override
80+
public ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException {
81+
return clarinLicenseLabelDAO.findByLabel(context, label);
82+
}
83+
7984
@Override
8085
public void delete(Context context, ClarinLicenseLabel license) throws SQLException, AuthorizeException {
8186
if (!authorizeService.isAdmin(context)) {

dspace-api/src/main/java/org/dspace/content/clarin/ClarinLicenseServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public List<ClarinLicense> findByNameLike(Context context, String name) throws S
9797
return clarinLicenseDAO.findByNameLike(context, name);
9898
}
9999

100+
@Override
101+
public List<ClarinLicense> findByLabel(Context context, String label) throws SQLException {
102+
return clarinLicenseDAO.findByLabel(context, label);
103+
}
104+
100105
@Override
101106
public void addLicenseMetadataToItem(Context context, ClarinLicense clarinLicense, Item item) throws SQLException {
102107
if (Objects.isNull(clarinLicense) || Objects.isNull(item)) {

dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseDAO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ public interface ClarinLicenseDAO extends GenericDAO<ClarinLicense> {
2828

2929
List<ClarinLicense> findByNameLike(Context context, String name) throws SQLException;
3030

31+
List<ClarinLicense> findByLabel(Context context, String label) throws SQLException;
32+
3133
}

dspace-api/src/main/java/org/dspace/content/dao/clarin/ClarinLicenseLabelDAO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
*/
88
package org.dspace.content.dao.clarin;
99

10+
import java.sql.SQLException;
11+
1012
import org.dspace.content.clarin.ClarinLicenseLabel;
13+
import org.dspace.core.Context;
1114
import org.dspace.core.GenericDAO;
1215

1316
/**
@@ -19,4 +22,6 @@
1922
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
2023
*/
2124
public interface ClarinLicenseLabelDAO extends GenericDAO<ClarinLicenseLabel> {
25+
26+
ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException;
2227
}

dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
import jakarta.persistence.Query;
1414
import jakarta.persistence.criteria.CriteriaBuilder;
1515
import jakarta.persistence.criteria.CriteriaQuery;
16+
import jakarta.persistence.criteria.Predicate;
1617
import jakarta.persistence.criteria.Root;
18+
import jakarta.persistence.criteria.SetJoin;
1719
import org.dspace.content.clarin.ClarinLicense;
20+
import org.dspace.content.clarin.ClarinLicenseLabel;
21+
import org.dspace.content.clarin.ClarinLicenseLabel_;
1822
import org.dspace.content.clarin.ClarinLicense_;
1923
import org.dspace.content.dao.clarin.ClarinLicenseDAO;
2024
import org.dspace.core.AbstractHibernateDAO;
@@ -54,4 +58,20 @@ public List<ClarinLicense> findByNameLike(Context context, String name) throws S
5458
criteriaQuery.orderBy(criteriaBuilder.asc(clarinLicenseRoot.get(ClarinLicense_.name)));
5559
return list(context, criteriaQuery, false, ClarinLicense.class, -1, -1);
5660
}
61+
62+
@Override
63+
public List<ClarinLicense> findByLabel(Context context, String label) throws SQLException {
64+
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
65+
CriteriaQuery<ClarinLicense> criteriaQuery = getCriteriaQuery(criteriaBuilder, ClarinLicense.class);
66+
Root<ClarinLicense> clarinLicenseRoot = criteriaQuery.from(ClarinLicense.class);
67+
68+
SetJoin<ClarinLicense, ClarinLicenseLabel> labelJoin =
69+
clarinLicenseRoot.joinSet(ClarinLicense_.CLARIN_LICENSE_LABELS);
70+
71+
Predicate labelPredicate = criteriaBuilder.equal(labelJoin.get(ClarinLicenseLabel_.LABEL), label);
72+
73+
criteriaQuery.select(clarinLicenseRoot).where(labelPredicate);
74+
75+
return list(context, criteriaQuery, false, ClarinLicense.class, -1, -1);
76+
}
5777
}

dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseLabelDAOImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
*/
88
package org.dspace.content.dao.impl.clarin;
99

10+
import java.sql.SQLException;
11+
12+
import jakarta.persistence.criteria.CriteriaBuilder;
13+
import jakarta.persistence.criteria.CriteriaQuery;
14+
import jakarta.persistence.criteria.Root;
1015
import org.dspace.content.clarin.ClarinLicenseLabel;
16+
import org.dspace.content.clarin.ClarinLicenseLabel_;
1117
import org.dspace.content.dao.clarin.ClarinLicenseLabelDAO;
1218
import org.dspace.core.AbstractHibernateDAO;
19+
import org.dspace.core.Context;
1320

1421
/**
1522
* Hibernate implementation of the Database Access Object interface class for the Clarin License Label object.
@@ -23,4 +30,14 @@ public class ClarinLicenseLabelDAOImpl extends AbstractHibernateDAO<ClarinLicens
2330
protected ClarinLicenseLabelDAOImpl() {
2431
super();
2532
}
33+
34+
@Override
35+
public ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException {
36+
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
37+
CriteriaQuery<ClarinLicenseLabel> criteriaQuery = getCriteriaQuery(criteriaBuilder, ClarinLicenseLabel.class);
38+
Root<ClarinLicenseLabel> cllRoot = criteriaQuery.from(ClarinLicenseLabel.class);
39+
criteriaQuery.select(cllRoot);
40+
criteriaQuery.where(criteriaBuilder.equal(cllRoot.get(ClarinLicenseLabel_.label), label));
41+
return uniqueResult(context, criteriaQuery, true, ClarinLicenseLabel.class);
42+
}
2643
}

dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseLabelService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ ClarinLicenseLabel create(Context context, ClarinLicenseLabel clarinLicenseLabel
5252
*/
5353
ClarinLicenseLabel find(Context context, int valueId) throws SQLException;
5454

55+
/**
56+
* Find the clarin license label object by label name
57+
*
58+
* @param context DSpace context object
59+
* @param label label name of the searching clarin license label object
60+
* @return found clarin license label object or null
61+
* @throws SQLException if database error
62+
*/
63+
ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException;
64+
5565
/**
5666
* Find all clarin license label objects
5767
* @param context DSpace context object

dspace-api/src/main/java/org/dspace/content/service/clarin/ClarinLicenseService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ public interface ClarinLicenseService {
7777
*/
7878
List<ClarinLicense> findByNameLike(Context context, String name) throws SQLException;
7979

80+
/**
81+
* Find Clarin Licenses by the license label.
82+
*
83+
* @param context DSpace context object
84+
* @param label the license label
85+
* @return List of clarin licenses which contain the specified license label.
86+
* @throws SQLException if database error
87+
*/
88+
List<ClarinLicense> findByLabel(Context context, String label) throws SQLException;
89+
8090
void addLicenseMetadataToItem(Context context, ClarinLicense clarinLicense, Item item) throws SQLException;
8191

8292
void clearLicenseMetadataFromItem(Context context, Item item) throws SQLException;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--
2+
-- The contents of this file are subject to the license and copyright
3+
-- detailed in the LICENSE and NOTICE files at the root of the source
4+
-- tree and available online at
5+
--
6+
-- http://www.dspace.org/license/
7+
--
8+
9+
ALTER TABLE license_label_extended_mapping
10+
DROP CONSTRAINT IF EXISTS license_label_license_label_extended_mapping_fk;
11+
12+
-- here the "ON DELETE RESTRICT" clause (default clause) is used, which prevents deletion of a license_label record
13+
-- when there are any license_label_extended_mapping records that reference it
14+
ALTER TABLE license_label_extended_mapping
15+
ADD CONSTRAINT license_label_license_label_extended_mapping_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id);
16+
17+
ALTER TABLE license_label DROP CONSTRAINT IF EXISTS license_label_label_unique;
18+
ALTER TABLE license_label ADD CONSTRAINT license_label_label_unique UNIQUE(label);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--
2+
-- The contents of this file are subject to the license and copyright
3+
-- detailed in the LICENSE and NOTICE files at the root of the source
4+
-- tree and available online at
5+
--
6+
-- http://www.dspace.org/license/
7+
--
8+
9+
ALTER TABLE license_label_extended_mapping
10+
DROP CONSTRAINT IF EXISTS license_label_license_label_extended_mapping_fk;
11+
12+
-- here the "ON DELETE RESTRICT" clause (default clause) is used, which prevents deletion of a license_label record
13+
-- when there are any license_label_extended_mapping records that reference it
14+
ALTER TABLE license_label_extended_mapping
15+
ADD CONSTRAINT license_label_license_label_extended_mapping_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id);
16+
17+
ALTER TABLE license_label DROP CONSTRAINT IF EXISTS license_label_label_unique;
18+
ALTER TABLE license_label ADD CONSTRAINT license_label_label_unique UNIQUE(label);

0 commit comments

Comments
 (0)