Skip to content

Commit

Permalink
Add duplicated Strings as constants
Browse files Browse the repository at this point in the history
  • Loading branch information
bencomp committed Aug 4, 2024
1 parent b6443aa commit fe040d9
Show file tree
Hide file tree
Showing 151 changed files with 3,581 additions and 2,483 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Stateless
@Named
public class AuxiliaryFileServiceBean implements java.io.Serializable {
private static final String DATA_FILE_ID = "dataFileId";
private static final Logger logger = Logger.getLogger(AuxiliaryFileServiceBean.class.getCanonicalName());

@PersistenceContext(unitName = "VDCNet-ejbPU")
Expand Down Expand Up @@ -158,7 +159,7 @@ public AuxiliaryFile lookupAuxiliaryFile(DataFile dataFile, String formatTag, St

Query query = em.createNamedQuery("AuxiliaryFile.lookupAuxiliaryFile");

query.setParameter("dataFileId", dataFile.getId());
query.setParameter(DATA_FILE_ID, dataFile.getId());
query.setParameter("formatTag", formatTag);
query.setParameter("formatVersion", formatVersion);
try {
Expand All @@ -179,7 +180,7 @@ public List<AuxiliaryFile> findAuxiliaryFiles(DataFile dataFile, String origin)
query = em.createNamedQuery("AuxiliaryFile.findAuxiliaryFilesByOrigin", AuxiliaryFile.class);
query.setParameter("origin", origin);
}
query.setParameter("dataFileId", dataFile.getId());
query.setParameter(DATA_FILE_ID, dataFile.getId());

List<AuxiliaryFile> retVal = query.getResultList();
return retVal;
Expand Down Expand Up @@ -210,7 +211,7 @@ public void deleteAuxiliaryFile(DataFile dataFile, String formatTag, String form

public List<AuxiliaryFile> findAuxiliaryFiles(DataFile dataFile) {
TypedQuery<AuxiliaryFile> query = em.createNamedQuery("AuxiliaryFile.findAuxiliaryFiles", AuxiliaryFile.class);
query.setParameter("dataFileId", dataFile.getId());
query.setParameter(DATA_FILE_ID, dataFile.getId());
return query.getResultList();
}

Expand Down Expand Up @@ -246,7 +247,7 @@ public List<String> findAuxiliaryFileTypes(DataFile dataFile) {

public List<AuxiliaryFile> findAuxiliaryFilesByType(DataFile dataFile, String typeString) {
TypedQuery<AuxiliaryFile> query = em.createNamedQuery("AuxiliaryFile.findAuxiliaryFilesByType", AuxiliaryFile.class);
query.setParameter("dataFileId", dataFile.getId());
query.setParameter(DATA_FILE_ID, dataFile.getId());
query.setParameter("type", typeString);
return query.getResultList();
}
Expand All @@ -256,7 +257,7 @@ public List<AuxiliaryFile> findOtherAuxiliaryFiles(DataFile dataFile) {
List<String> otherTypes = findAuxiliaryFileTypes(dataFile, false);
for (String typeString : otherTypes) {
TypedQuery<AuxiliaryFile> query = em.createNamedQuery("AuxiliaryFile.findAuxiliaryFilesByType", AuxiliaryFile.class);
query.setParameter("dataFileId", dataFile.getId());
query.setParameter(DATA_FILE_ID, dataFile.getId());
query.setParameter("type", typeString);
List<AuxiliaryFile> auxFiles = query.getResultList();
otherAuxFiles.addAll(auxFiles);
Expand All @@ -267,7 +268,7 @@ public List<AuxiliaryFile> findOtherAuxiliaryFiles(DataFile dataFile) {

public List<AuxiliaryFile> findAuxiliaryFilesWithoutType(DataFile dataFile) {
TypedQuery<AuxiliaryFile> query = em.createNamedQuery("AuxiliaryFile.findAuxiliaryFilesWithoutType", AuxiliaryFile.class);
query.setParameter("dataFileId", dataFile.getId());
query.setParameter(DATA_FILE_ID, dataFile.getId());
return query.getResultList();
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/DataCitation.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
*/
public class DataCitation {

private static final String AUTHOR = "author";

private static final Logger logger = Logger.getLogger(DataCitation.class.getCanonicalName());

private List<String> authors = new ArrayList<>();
Expand Down Expand Up @@ -469,7 +471,7 @@ private void createEndNoteXML(XMLStreamWriter xmlw) throws XMLStreamException {
if (!authors.isEmpty()) {
xmlw.writeStartElement("authors");
for (String author : authors) {
xmlw.writeStartElement("author");
xmlw.writeStartElement(AUTHOR);
xmlw.writeCharacters(author);
xmlw.writeEndElement(); // author
}
Expand All @@ -478,7 +480,7 @@ private void createEndNoteXML(XMLStreamWriter xmlw) throws XMLStreamException {
if (!producers.isEmpty()) {
xmlw.writeStartElement("secondary-authors");
for (String producer : producers) {
xmlw.writeStartElement("author");
xmlw.writeStartElement(AUTHOR);
xmlw.writeCharacters(producer);
xmlw.writeEndElement(); // author
}
Expand All @@ -487,7 +489,7 @@ private void createEndNoteXML(XMLStreamWriter xmlw) throws XMLStreamException {
if (!funders.isEmpty()) {
xmlw.writeStartElement("subsidiary-authors");
for (String funder : funders) {
xmlw.writeStartElement("author");
xmlw.writeStartElement(AUTHOR);
xmlw.writeCharacters(funder);
xmlw.writeEndElement(); // author
}
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/edu/harvard/iq/dataverse/DataFileServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
@Named
public class DataFileServiceBean implements java.io.Serializable {

private static final String ORDER_BY_O = " order by o.";

private static final String DATASET_VERSION_ID = "datasetVersionId";

private static final String FILE_ID = "fileId";

private static final Logger logger = Logger.getLogger(DataFileServiceBean.class.getCanonicalName());
@EJB
DvObjectServiceBean dvObjectService;
Expand Down Expand Up @@ -277,7 +283,7 @@ public List<FileMetadata> findFileMetadataByDatasetVersionId(Long datasetVersion
}
String qr = "select o from FileMetadata o where o.datasetVersion.id = :datasetVersionId order by o." + sortField + " " + sortOrder;
return em.createQuery(qr, FileMetadata.class)
.setParameter("datasetVersionId", datasetVersionId)
.setParameter(DATASET_VERSION_ID, datasetVersionId)
.setMaxResults(maxResults)
.getResultList();
}
Expand All @@ -294,9 +300,9 @@ public List<FileMetadata> findFileMetadataByDatasetVersionIdLabelSearchTerm(Long

String queryString = "select o from FileMetadata o where o.datasetVersion.id = :datasetVersionId"
+ searchClause
+ " order by o." + sortField + " " + sortOrder;
+ ORDER_BY_O + sortField + " " + sortOrder;
return em.createQuery(queryString, FileMetadata.class)
.setParameter("datasetVersionId", datasetVersionId)
.setParameter(DATASET_VERSION_ID, datasetVersionId)
.getResultList();
}

Expand All @@ -316,7 +322,7 @@ public List<Integer> findFileMetadataIdsByDatasetVersionIdLabelSearchTerm(Long d
//as the second parameter.
return em.createNativeQuery("select o.id from FileMetadata o where o.datasetVersion_id = " + datasetVersionId
+ searchClause
+ " order by o." + sortField + " " + sortOrder)
+ ORDER_BY_O + sortField + " " + sortOrder)
.getResultList();
}

Expand All @@ -333,7 +339,7 @@ public List<Long> findDataFileIdsByDatasetVersionIdLabelSearchTerm(Long datasetV

return em.createNativeQuery("select o.datafile_id from FileMetadata o where o.datasetVersion_id = " + datasetVersionId
+ searchClause
+ " order by o." + sortField + " " + sortOrder)
+ ORDER_BY_O + sortField + " " + sortOrder)
.getResultList();
}

Expand All @@ -347,7 +353,7 @@ public List<FileMetadata> findFileMetadataByDatasetVersionIdLazy(Long datasetVer
maxResults = 0;
}
return em.createQuery("select o from FileMetadata o where o.datasetVersion.id = :datasetVersionId order by o." + sortField + " " + sortOrder, FileMetadata.class)
.setParameter("datasetVersionId", datasetVersionId)
.setParameter(DATASET_VERSION_ID, datasetVersionId)
.setMaxResults(maxResults)
.setFirstResult(firstResult)
.getResultList();
Expand All @@ -366,7 +372,7 @@ public FileMetadata findFileMetadata(Long fileMetadataId) {
public FileMetadata findFileMetadataByDatasetVersionIdAndDataFileId(Long datasetVersionId, Long dataFileId) {

Query query = em.createQuery("select o from FileMetadata o where o.datasetVersion.id = :datasetVersionId and o.dataFile.id = :dataFileId");
query.setParameter("datasetVersionId", datasetVersionId);
query.setParameter(DATASET_VERSION_ID, datasetVersionId);
query.setParameter("dataFileId", dataFileId);
try {
FileMetadata retVal = (FileMetadata) query.getSingleResult();
Expand Down Expand Up @@ -746,7 +752,7 @@ public List<DataFile> findIngestsInProgress() {

public DataTable findDataTableByFileId(Long fileId) {
Query query = em.createQuery("select object(o) from DataTable as o where o.dataFile.id =:fileId order by o.id");
query.setParameter("fileId", fileId);
query.setParameter(FILE_ID, fileId);

Object singleResult;

Expand All @@ -764,7 +770,7 @@ public List<DataFile> findAll() {
public List<VersionState> findVersionStates(Long fileId) {
Query query = em.createQuery(
"select distinct dv.versionState from DatasetVersion dv where dv.id in (select fm.datasetVersion.id from FileMetadata fm where fm.dataFile.id=:fileId)");
query.setParameter("fileId", fileId);
query.setParameter(FILE_ID, fileId);
return query.getResultList();
}

Expand Down Expand Up @@ -833,14 +839,14 @@ public DataFile setAndCheckFileReplaceAttributes(DataFile savedDataFile) {

public Boolean isPreviouslyPublished(Long fileId) {
Query query = em.createQuery("select object(o) from FileMetadata as o where o.dataFile.id =:fileId");
query.setParameter("fileId", fileId);
query.setParameter(FILE_ID, fileId);
List<?> retList = query.getResultList();
return (retList.size() > 1);
}

public void deleteFromVersion(DatasetVersion d, DataFile f) {
em.createNamedQuery("DataFile.removeFromDatasetVersion")
.setParameter("versionId", d.getId()).setParameter("fileId", f.getId())
.setParameter("versionId", d.getId()).setParameter(FILE_ID, f.getId())
.executeUpdate();
}

Expand Down
Loading

0 comments on commit fe040d9

Please sign in to comment.