Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public List<ClarinLicenseLabel> findAll(Context context) throws SQLException, Au
return clarinLicenseLabelDAO.findAll(context, ClarinLicenseLabel.class);
}

@Override
public ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException {
return clarinLicenseLabelDAO.findByLabel(context, label);
}

@Override
public void delete(Context context, ClarinLicenseLabel license) throws SQLException, AuthorizeException {
if (!authorizeService.isAdmin(context)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public List<ClarinLicense> findByNameLike(Context context, String name) throws S
return clarinLicenseDAO.findByNameLike(context, name);
}

@Override
public List<ClarinLicense> findByLabel(Context context, String label) throws SQLException {
return clarinLicenseDAO.findByLabel(context, label);
}

@Override
public void addLicenseMetadataToItem(Context context, ClarinLicense clarinLicense, Item item) throws SQLException {
if (Objects.isNull(clarinLicense) || Objects.isNull(item)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface ClarinLicenseDAO extends GenericDAO<ClarinLicense> {

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

List<ClarinLicense> findByLabel(Context context, String label) throws SQLException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/
package org.dspace.content.dao.clarin;

import java.sql.SQLException;

import org.dspace.content.clarin.ClarinLicenseLabel;
import org.dspace.core.Context;
import org.dspace.core.GenericDAO;

/**
Expand All @@ -19,4 +22,6 @@
* @author Milan Majchrak (milan.majchrak at dataquest.sk)
*/
public interface ClarinLicenseLabelDAO extends GenericDAO<ClarinLicenseLabel> {

ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.SetJoin;

import org.dspace.content.clarin.ClarinLicense;
import org.dspace.content.clarin.ClarinLicenseLabel;
import org.dspace.content.clarin.ClarinLicenseLabel_;
import org.dspace.content.clarin.ClarinLicense_;
import org.dspace.content.dao.clarin.ClarinLicenseDAO;
import org.dspace.core.AbstractHibernateDAO;
Expand Down Expand Up @@ -54,4 +58,20 @@ public List<ClarinLicense> findByNameLike(Context context, String name) throws S
criteriaQuery.orderBy(criteriaBuilder.asc(clarinLicenseRoot.get(ClarinLicense_.name)));
return list(context, criteriaQuery, false, ClarinLicense.class, -1, -1);
}

@Override
public List<ClarinLicense> findByLabel(Context context, String label) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery<ClarinLicense> criteriaQuery = getCriteriaQuery(criteriaBuilder, ClarinLicense.class);
Root<ClarinLicense> clarinLicenseRoot = criteriaQuery.from(ClarinLicense.class);

SetJoin<ClarinLicense, ClarinLicenseLabel> labelJoin =
clarinLicenseRoot.joinSet(ClarinLicense_.CLARIN_LICENSE_LABELS);

Predicate labelPredicate = criteriaBuilder.equal(labelJoin.get(ClarinLicenseLabel_.LABEL), label);

criteriaQuery.select(clarinLicenseRoot).where(labelPredicate);

return list(context, criteriaQuery, false, ClarinLicense.class, -1, -1);
}
Comment on lines +62 to +76

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add Javadoc for the public findByLabel method.

The new findByLabel method is public and overrides a DAO interface method, but lacks Javadoc documentation. As per coding guidelines, all public methods in Java should have Javadoc comments explaining parameters, return values, and exceptions.

📝 Suggested Javadoc
+    /**
+     * Find all Clarin Licenses that contain the specified license label.
+     *
+     * `@param` context DSpace context object
+     * `@param` label the license label to search for
+     * `@return` List of Clarin Licenses containing the specified label
+     * `@throws` SQLException if database error
+     */
     `@Override`
     public List<ClarinLicense> findByLabel(Context context, String label) throws SQLException {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@dspace-api/src/main/java/org/dspace/content/dao/impl/clarin/ClarinLicenseDAOImpl.java`
around lines 62 - 76, The public method findByLabel in ClarinLicenseDAOImpl is
missing Javadoc; add a standard Javadoc block above the method explaining the
purpose of findByLabel(Context context, String label), describing the parameters
(context and label), the return value (List<ClarinLicense>), and the thrown
SQLException, and include any behavioural notes (e.g., matching semantics or
null/empty handling) so the documentation meets project guidelines and documents
the contract of the overridden DAO method.

Source: Coding guidelines

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
*/
package org.dspace.content.dao.impl.clarin;

import java.sql.SQLException;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.dspace.content.clarin.ClarinLicenseLabel;
import org.dspace.content.clarin.ClarinLicenseLabel_;
import org.dspace.content.dao.clarin.ClarinLicenseLabelDAO;
import org.dspace.core.AbstractHibernateDAO;
import org.dspace.core.Context;

/**
* Hibernate implementation of the Database Access Object interface class for the Clarin License Label object.
Expand All @@ -23,4 +30,14 @@ public class ClarinLicenseLabelDAOImpl extends AbstractHibernateDAO<ClarinLicens
protected ClarinLicenseLabelDAOImpl() {
super();
}

@Override
public ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery<ClarinLicenseLabel> criteriaQuery = getCriteriaQuery(criteriaBuilder, ClarinLicenseLabel.class);
Root<ClarinLicenseLabel> cllRoot = criteriaQuery.from(ClarinLicenseLabel.class);
criteriaQuery.select(cllRoot);
criteriaQuery.where(criteriaBuilder.equal(cllRoot.get(ClarinLicenseLabel_.label), label));
return uniqueResult(context, criteriaQuery, true, ClarinLicenseLabel.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ ClarinLicenseLabel create(Context context, ClarinLicenseLabel clarinLicenseLabel
*/
ClarinLicenseLabel find(Context context, int valueId) throws SQLException;

/**
* Find the clarin license label object by label name
*
* @param context DSpace context object
* @param label label name of the searching clarin license label object
* @return found clarin license label object or null
* @throws SQLException if database error
*/
ClarinLicenseLabel findByLabel(Context context, String label) throws SQLException;

/**
* Find all clarin license label objects
* @param context DSpace context object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public interface ClarinLicenseService {
*/
List<ClarinLicense> findByNameLike(Context context, String name) throws SQLException;

/**
* Find Clarin Licenses by the license label.
*
* @param context DSpace context object
* @param label the license label
* @return List of clarin licenses which contain the specified license label.
* @throws SQLException if database error
*/
List<ClarinLicense> findByLabel(Context context, String label) throws SQLException;

void addLicenseMetadataToItem(Context context, ClarinLicense clarinLicense, Item item) throws SQLException;

void clearLicenseMetadataFromItem(Context context, Item item) throws SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--
-- The contents of this file are subject to the license and copyright
-- detailed in the LICENSE and NOTICE files at the root of the source
-- tree and available online at
--
-- http://www.dspace.org/license/
--

ALTER TABLE license_label_extended_mapping
DROP CONSTRAINT IF EXISTS license_label_license_label_extended_mapping_fk;

-- here the "ON DELETE RESTRICT" clause (default clause) is used, which prevents deletion of a license_label record
-- when there are any license_label_extended_mapping records that reference it
ALTER TABLE license_label_extended_mapping
ADD CONSTRAINT license_label_license_label_extended_mapping_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id);

ALTER TABLE license_label DROP CONSTRAINT IF EXISTS license_label_label_unique;
ALTER TABLE license_label ADD CONSTRAINT license_label_label_unique UNIQUE(label);
Comment on lines +17 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Guard the unique-constraint migration with duplicate-data handling.

Adding UNIQUE(label) can fail upgrades on instances that already contain duplicate license_label.label values. Add a preceding cleanup/preflight step (or deterministic dedup migration) before enforcing the constraint.

Example preflight query
SELECT label, COUNT(*)
FROM license_label
GROUP BY label
HAVING COUNT(*) > 1;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.6_2026.06.01__license_label_constraint.sql`
around lines 17 - 18, The migration unconditionally drops/adds the UNIQUE
constraint on license_label.label which will fail if duplicate labels exist;
before adding license_label_label_unique run a preflight duplicate check (SELECT
label, COUNT(*) ... HAVING COUNT(*) > 1) and implement a deterministic
dedup/upsert step to remove or merge duplicates (e.g. keep the earliest id or
newest timestamp) for rows with the same label, then re-run the ALTER TABLE to
add the UNIQUE constraint; reference the table name license_label and the
constraint name license_label_label_unique when adding the preflight check and
deterministic cleanup migration.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--
-- The contents of this file are subject to the license and copyright
-- detailed in the LICENSE and NOTICE files at the root of the source
-- tree and available online at
--
-- http://www.dspace.org/license/
--

ALTER TABLE license_label_extended_mapping
DROP CONSTRAINT IF EXISTS license_label_license_label_extended_mapping_fk;

-- here the "ON DELETE RESTRICT" clause (default clause) is used, which prevents deletion of a license_label record
-- when there are any license_label_extended_mapping records that reference it
ALTER TABLE license_label_extended_mapping
ADD CONSTRAINT license_label_license_label_extended_mapping_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id);

ALTER TABLE license_label DROP CONSTRAINT IF EXISTS license_label_label_unique;
ALTER TABLE license_label ADD CONSTRAINT license_label_label_unique UNIQUE(label);
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.dspace.builder.BitstreamFormatBuilder;
import org.dspace.builder.BundleBuilder;
import org.dspace.builder.ClaimedTaskBuilder;
import org.dspace.builder.ClarinLicenseBuilder;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

ClarinLicenseLabelBuilder is missing from the cleanup order.

ClarinLicenseBuilder has been added to the cleanup map, but ClarinLicenseLabelBuilder is absent. Based on the REST repository's delete guard (lines 159-163 in ClarinLicenseLabelRestRepository.java), licenses reference labels, creating a foreign key dependency. The cleanup order must delete licenses before labels to avoid constraint violations.

Add ClarinLicenseLabelBuilder to the map after line 89 so licenses are cleaned up first:

🔧 Suggested fix
 import org.dspace.builder.ClarinLicenseBuilder;
+import org.dspace.builder.ClarinLicenseLabelBuilder;
 import org.dspace.builder.CollectionBuilder;
         map.put(ClarinLicenseBuilder.class.getName(), new ArrayList<>());
+        map.put(ClarinLicenseLabelBuilder.class.getName(), new ArrayList<>());
     }

Also applies to: 89-89

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@dspace-api/src/test/java/org/dspace/builder/util/AbstractBuilderCleanupUtil.java`
at line 20, The cleanup map in AbstractBuilderCleanupUtil now includes
ClarinLicenseBuilder but is missing ClarinLicenseLabelBuilder, causing FK
deletion order issues; update the cleanup map in the AbstractBuilderCleanupUtil
class to add ClarinLicenseLabelBuilder immediately after the existing
ClarinLicenseBuilder entry so that ClarinLicenseBuilder (licenses) are removed
before ClarinLicenseLabelBuilder (labels), ensuring deletions obey the
foreign-key constraint referenced by ClarinLicenseLabelRestRepository; locate
the map population code (the entries involving ClarinLicenseBuilder) and insert
the ClarinLicenseLabelBuilder entry right after it.

import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.EPersonBuilder;
Expand Down Expand Up @@ -85,6 +86,7 @@ private void initMap() {
map.put(SiteBuilder.class.getName(), new ArrayList<>());
map.put(ProcessBuilder.class.getName(), new ArrayList<>());
map.put(PreviewContentBuilder.class.getName(), new ArrayList<>());
map.put(ClarinLicenseBuilder.class.getName(), new ArrayList<>());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.exception;

import javax.ws.rs.NotFoundException;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
* Exception thrown when Clarin License Label not found
*
* @author Milan Kuchtiak
*/
@ResponseStatus(HttpStatus.NOT_FOUND)
public class ClarinLicenseLabelNotFoundException extends NotFoundException {

public ClarinLicenseLabelNotFoundException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.exception.ClarinLicenseLabelNotFoundException;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.ClarinLicenseLabelRest;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.clarin.ClarinLicense;
import org.dspace.content.clarin.ClarinLicenseLabel;
import org.dspace.content.service.clarin.ClarinLicenseLabelService;
import org.dspace.content.service.clarin.ClarinLicenseService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
Expand All @@ -36,9 +41,17 @@
@Component(ClarinLicenseLabelRest.CATEGORY + "." + ClarinLicenseLabelRest.NAME)
public class ClarinLicenseLabelRestRepository extends DSpaceRestRepository<ClarinLicenseLabelRest, Integer> {

private static final int MAX_LABEL_LENGTH = 5;

@Autowired
ClarinLicenseService clarinLicenseService;

@Autowired
ClarinLicenseLabelService clarinLicenseLabelService;

@Autowired
ObjectMapper objectMapper;

@Override
public ClarinLicenseLabelRest findOne(Context context, Integer id) {
ClarinLicenseLabel clarinLicenseLabel;
Expand Down Expand Up @@ -72,35 +85,107 @@ protected ClarinLicenseLabelRest createAndReturn(Context context)
// parse request body
ClarinLicenseLabelRest clarinLicenseLabelRest;
try {
clarinLicenseLabelRest = new ObjectMapper().readValue(
clarinLicenseLabelRest = objectMapper.readValue(
getRequestService().getCurrentRequest().getHttpServletRequest().getInputStream(),
ClarinLicenseLabelRest.class
);
} catch (IOException excIO) {
throw new DSpaceBadRequestException("error parsing request body", excIO);
}

// validate fields
if (isBlank(clarinLicenseLabelRest.getLabel()) || isBlank(clarinLicenseLabelRest.getTitle())) {
throw new UnprocessableEntityException("CLARIN License Label title, label, icon cannot be null or empty");
checkLabelAndTitle(clarinLicenseLabelRest);
if (clarinLicenseLabelService.findByLabel(context, clarinLicenseLabelRest.getLabel().trim()) != null) {
throw new DSpaceBadRequestException("Clarin License Label with label " + clarinLicenseLabelRest.getLabel() +
" already exists");
}

// create
ClarinLicenseLabel clarinLicenseLabel;
clarinLicenseLabel = clarinLicenseLabelService.create(context);
// if (Objects.nonNull(clarinLicenseLabelRest.getId())) {
// clarinLicenseLabel.setId(clarinLicenseLabelRest.getId());
// }
clarinLicenseLabel.setLabel(clarinLicenseLabelRest.getLabel());
clarinLicenseLabel.setTitle(clarinLicenseLabelRest.getTitle());
clarinLicenseLabel.setIcon(clarinLicenseLabelRest.getIcon());
clarinLicenseLabel.setExtended(clarinLicenseLabelRest.isExtended());
updateClarinLicenseLabel(clarinLicenseLabel, clarinLicenseLabelRest);

clarinLicenseLabelService.update(context, clarinLicenseLabel);
// return
return converter.toRest(clarinLicenseLabel, utils.obtainProjection());
}

@Override
@PreAuthorize("hasAuthority('ADMIN')")
public ClarinLicenseLabelRest put(Context context,
HttpServletRequest request,
String apiCategory,
String model,
Integer id,
JsonNode jsonNode) throws SQLException, AuthorizeException {
ClarinLicenseLabel clarinLicenseLabel = clarinLicenseLabelService.find(context, id);
if (Objects.isNull(clarinLicenseLabel)) {
throw new ClarinLicenseLabelNotFoundException("Clarin License Label with id " + id + " was not found");
}

// parse request body
ClarinLicenseLabelRest clarinLicenseLabelRest;
try {
clarinLicenseLabelRest = objectMapper.treeToValue(jsonNode, ClarinLicenseLabelRest.class);
} catch (IOException excIO) {
throw new DSpaceBadRequestException("error parsing request body", excIO);
}

checkLabelAndTitle(clarinLicenseLabelRest);

ClarinLicenseLabel clarinLicenseLabelWithSameLabel = clarinLicenseLabelService.findByLabel(context,
clarinLicenseLabelRest.getLabel().trim());
if (clarinLicenseLabelWithSameLabel != null && !clarinLicenseLabelWithSameLabel.getID().equals(id)) {
throw new DSpaceBadRequestException("Clarin License Label with label " + clarinLicenseLabelRest.getLabel() +
" already exists");
}

clarinLicenseLabel.setId(id);
updateClarinLicenseLabel(clarinLicenseLabel, clarinLicenseLabelRest);

clarinLicenseLabelService.update(context, clarinLicenseLabel);

return converter.toRest(clarinLicenseLabel, utils.obtainProjection());
}
Comment on lines +112 to +148

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add Javadoc for the public put method.

The put method is a public REST endpoint handler but lacks Javadoc documentation. As per coding guidelines, all public methods in Java should have Javadoc comments explaining parameters, return values, and exceptions.

📝 Suggested Javadoc
+    /**
+     * Update a Clarin License Label by ID.
+     *
+     * `@param` context DSpace context object
+     * `@param` request HTTP servlet request
+     * `@param` apiCategory API category
+     * `@param` model model name
+     * `@param` id ID of the license label to update (from path)
+     * `@param` jsonNode request body containing updated fields
+     * `@return` updated Clarin License Label REST object
+     * `@throws` SQLException if database error
+     * `@throws` AuthorizeException if user is not authorized
+     */
     `@Override`
     `@PreAuthorize`("hasAuthority('ADMIN')")
     public ClarinLicenseLabelRest put(Context context,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinLicenseLabelRestRepository.java`
around lines 112 - 148, Add a Javadoc comment to the public method put in
ClarinLicenseLabelRestRepository: document the purpose of the endpoint, describe
each parameter (Context context, HttpServletRequest request, String apiCategory,
String model, Integer id, JsonNode jsonNode), explain the return value
(ClarinLicenseLabelRest via converter.toRest), and list thrown exceptions
(SQLException, AuthorizeException, DSpaceBadRequestException,
ClarinLicenseLabelNotFoundException). Keep the description concise and mention
relevant behavior such as parsing with objectMapper.treeToValue, validation via
checkLabelAndTitle, uniqueness check via clarinLicenseLabelService.findByLabel,
and that the entity is updated with updateClarinLicenseLabel and
clarinLicenseLabelService.update.

Source: Coding guidelines


@Override
@PreAuthorize("hasAuthority('ADMIN')")
public void delete(Context context, Integer id) throws AuthorizeException {
ClarinLicenseLabel clarinLicenseLabel;
try {
clarinLicenseLabel = clarinLicenseLabelService.find(context, id);
if (Objects.isNull(clarinLicenseLabel)) {
throw new ClarinLicenseLabelNotFoundException("Clarin License Label with id " + id + " was not found");
}
List<ClarinLicense> licenses = clarinLicenseService.findByLabel(context, clarinLicenseLabel.getLabel());
if (!licenses.isEmpty()) {
throw new DSpaceBadRequestException("Clarin License Label " + clarinLicenseLabel.getLabel() +
" is in use and cannot be deleted");
}
clarinLicenseLabelService.delete(context, clarinLicenseLabel);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Comment on lines +150 to +168

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add Javadoc for the public delete method.

The delete method is a public REST endpoint handler but lacks Javadoc documentation. As per coding guidelines, all public methods in Java should have Javadoc comments explaining parameters and exceptions.

📝 Suggested Javadoc
+    /**
+     * Delete a Clarin License Label by ID.
+     * Deletion is rejected if the label is in use by any Clarin License.
+     *
+     * `@param` context DSpace context object
+     * `@param` id ID of the license label to delete
+     * `@throws` AuthorizeException if user is not authorized
+     */
     `@Override`
     `@PreAuthorize`("hasAuthority('ADMIN')")
     public void delete(Context context, Integer id) throws AuthorizeException {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
@PreAuthorize("hasAuthority('ADMIN')")
public void delete(Context context, Integer id) throws AuthorizeException {
ClarinLicenseLabel clarinLicenseLabel;
try {
clarinLicenseLabel = clarinLicenseLabelService.find(context, id);
if (Objects.isNull(clarinLicenseLabel)) {
throw new ClarinLicenseLabelNotFoundException("Clarin License Label with id " + id + " was not found");
}
List<ClarinLicense> licenses = clarinLicenseService.findByLabel(context, clarinLicenseLabel.getLabel());
if (!licenses.isEmpty()) {
throw new DSpaceBadRequestException("Clarin License Label " + clarinLicenseLabel.getLabel() +
" is in use and cannot be deleted");
}
clarinLicenseLabelService.delete(context, clarinLicenseLabel);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
/**
* Delete a Clarin License Label by ID.
* Deletion is rejected if the label is in use by any Clarin License.
*
* `@param` context DSpace context object
* `@param` id ID of the license label to delete
* `@throws` AuthorizeException if user is not authorized
*/
`@Override`
`@PreAuthorize`("hasAuthority('ADMIN')")
public void delete(Context context, Integer id) throws AuthorizeException {
ClarinLicenseLabel clarinLicenseLabel;
try {
clarinLicenseLabel = clarinLicenseLabelService.find(context, id);
if (Objects.isNull(clarinLicenseLabel)) {
throw new ClarinLicenseLabelNotFoundException("Clarin License Label with id " + id + " was not found");
}
List<ClarinLicense> licenses = clarinLicenseService.findByLabel(context, clarinLicenseLabel.getLabel());
if (!licenses.isEmpty()) {
throw new DSpaceBadRequestException("Clarin License Label " + clarinLicenseLabel.getLabel() +
" is in use and cannot be deleted");
}
clarinLicenseLabelService.delete(context, clarinLicenseLabel);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinLicenseLabelRestRepository.java`
around lines 150 - 168, Add Javadoc to the public method delete(Context context,
Integer id) in ClarinLicenseLabelRestRepository: document the purpose of the
method (deletes a ClarinLicenseLabel by id), describe parameters `@param` context
and `@param` id, and list thrown exceptions with `@throws` for AuthorizeException,
ClarinLicenseLabelNotFoundException, DSpaceBadRequestException and any
runtime/SQL-related exceptions that can propagate (e.g., RuntimeException
wrapping SQLException); also include a brief note about the
`@PreAuthorize`("hasAuthority('ADMIN')") security requirement. Ensure the Javadoc
sits immediately above the delete method signature.

Source: Coding guidelines


private void checkLabelAndTitle(ClarinLicenseLabelRest clarinLicenseLabelRest) {
String label = Optional.ofNullable(clarinLicenseLabelRest.getLabel()).map(String::trim).orElse(null);
// validate fields
if (isBlank(label) || isBlank(clarinLicenseLabelRest.getTitle())) {
throw new DSpaceBadRequestException("CLARIN License Label title and label cannot be null or empty");
}
if (label.length() > MAX_LABEL_LENGTH) {
throw new DSpaceBadRequestException(
"CLARIN License Label -> label string cannot be longer than " + MAX_LABEL_LENGTH + " characters");
}
}

private static void updateClarinLicenseLabel(ClarinLicenseLabel clarinLicenseLabel,
ClarinLicenseLabelRest clarinLicenseLabelRest) {
clarinLicenseLabel.setLabel(clarinLicenseLabelRest.getLabel().trim());
clarinLicenseLabel.setTitle(clarinLicenseLabelRest.getTitle());
clarinLicenseLabel.setIcon(clarinLicenseLabelRest.getIcon());
clarinLicenseLabel.setExtended(clarinLicenseLabelRest.isExtended());
}

@Override
public Class<ClarinLicenseLabelRest> getDomainClass() {
Expand Down
Loading
Loading