Skip to content

Commit

Permalink
archive-mgr: archive type processing added for get and count methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DenChaykovskiy committed Apr 3, 2024
1 parent f95c78d commit ae620cd
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import de.dlr.proseo.logging.messages.GeneralMessage;
import de.dlr.proseo.logging.messages.ProductArchiveMgrMessage;
import de.dlr.proseo.model.ProductArchive;
import de.dlr.proseo.model.enums.ArchiveType;
import de.dlr.proseo.model.service.RepositoryService;
import de.dlr.proseo.model.service.SecurityService;

Expand Down Expand Up @@ -284,8 +285,13 @@ public List<RestProductArchive> getArchives(String name, String archiveType, Int
if (null != name) {
query.setParameter("name", name);
}
if (null != archiveType) {
query.setParameter("archiveType", archiveType);

try {
if (null != archiveType) {
query.setParameter("archiveType", ArchiveType.valueOf(archiveType));
}
} catch (Exception e) {
throw new NoResultException(logger.log(ProductArchiveMgrMessage.ARCHIVE_NOT_FOUND, name, archiveType));
}

query.setFirstResult(recordFrom);
Expand Down Expand Up @@ -327,8 +333,15 @@ public String countArchives(String name, String archiveType) {

if (name != null)
predicates.add(cb.equal(rootArchive.get("name"), name));
if (archiveType != null)
predicates.add(cb.equal(rootArchive.get("archiveType"), archiveType));

try {
if (archiveType != null)
predicates.add(cb.equal(rootArchive.get("archiveType"), ArchiveType.valueOf(archiveType)));
}
catch (Exception e) {
logger.trace("... wrong archive type: " + archiveType);
return "0";
}

query.select(cb.count(rootArchive)).where(predicates.toArray(new Predicate[predicates.size()]));
Long result = em.createQuery(query).getSingleResult();
Expand Down

0 comments on commit ae620cd

Please sign in to comment.