try {
tx = em.getTransaction();
tx.begin();
// Get the directory description data from database
Directory directory = null;
try {
// Select distinct for objectDB which returns duplicated entries !
directory = em.createQuery(
"select distinct directory from Directory directory where directory.path = ?1", Directory.class)
.setParameter(1, path).getSingleResult();
// RBAC
AccessController.checkAuthorization(directory, request, Action.browse, em);
} catch (NoResultException ex) {
getServletContext().log(
"No directory data for: " + path, ex);
}
// Create Json response
JsonObject rsp = new JsonObject();
// Get the directory specific data
if ((directory != null) && (directory.isIndexingAllowedBoolean())) {
if (directory.getDescription() != null) {
rsp.addParameter(Configuration.dirDescParam, directory.getDescription());
}
if (directory.getLatitude() != null) {
rsp.addParameter(Configuration.latParam, directory.getLatitude());
}
if (directory.getLongitude() != null) {
rsp.addParameter(Configuration.lngParam, directory.getLongitude());
}
if (directory.getDate() != null) {
rsp.addParameter(Configuration.dirDateParam, directory.getDate());
}
rsp.addParameter(Configuration.groupParam,
(directory.getGroup() == null ? Configuration.publicGroup : directory.getGroup().getGroupName()));
List<Attribute> dirAttributes = directory.getAttributes();
if (dirAttributes != null) {
JsonArray attributes = new JsonArray();
for (Attribute attribute: dirAttributes) {
attributes.addItem(attribute.getName());
}