use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class MetadataController method searchByMetadata.
@RequestMapping(value = "/search/", method = RequestMethod.POST)
@ResponseBody
public String searchByMetadata(@RequestParam(required = false) final String jsonMetadataSearch, @RequestParam("draw") final int draw, @RequestParam("start") final int start, @RequestParam("length") final int length) throws DataGridConnectionRefusedException {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonResponse = new HashMap<String, Object>();
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(0));
jsonResponse.put("recordsFiltered", String.valueOf(0));
jsonResponse.put("data", new ArrayList<String>());
String jsonString = "";
try {
if (jsonMetadataSearch != null) {
currPage = (int) (Math.floor(start / length) + 1);
this.jsonMetadataSearch = jsonMetadataSearch;
}
// Creating parser
JsonNode jsonObject = mapper.readTree(this.jsonMetadataSearch);
currSearch = new ArrayList<>();
JsonNode attributes = jsonObject.get("attribute");
JsonNode operators = jsonObject.get("operator");
JsonNode values = jsonObject.get("value");
JsonNode units = jsonObject.get("unit");
for (int i = 0; i < attributes.size(); i++) {
String attr = attributes.get(i).textValue();
String val = values.get(i).textValue();
String unit = units.get(i).textValue();
String opt = operators.get(i).textValue();
DataGridSearchOperatorEnum op = DataGridSearchOperatorEnum.valueOf(opt);
DataGridMetadataSearch ms = new DataGridMetadataSearch(attr, val, unit, op);
currSearch.add(ms);
}
DataGridPageContext pageContext = new DataGridPageContext();
List<DataGridCollectionAndDataObject> dgCollDataObjs = metadataService.findByMetadata(currSearch, pageContext, currPage, length);
jsonResponse.put("recordsTotal", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("recordsFiltered", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("data", dgCollDataObjs);
} catch (DataGridConnectionRefusedException e) {
throw e;
} catch (Exception e) {
logger.error("Could not search by metadata: ", e.getMessage());
}
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (JsonProcessingException e) {
logger.error("Could not parse hashmap in metadata search to json: {}", e.getMessage());
}
return jsonString;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class PreviewPreparationController method getPreview.
/**
* Responds the preview/ request
*
* @param model
* @return the collection management template
* @throws DataGridConnectionRefusedException
* @throws JargonException
* @throws DataGridException
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String getPreview(final Model model, @RequestParam("path") final String path, RedirectAttributes redirectAttributes) throws DataGridException {
logger.info("prepareForPreview for {} ::" + path);
String mimeType = null;
boolean permission = previewService.getPermission(path);
if (permission) {
try {
IRODSAccount irodsAccount = irodsServices.getUserAO().getIRODSAccount();
DataTypeResolutionService dataTypeResolutionService = dataTypeResolutionServiceFactory.instanceDataTypeResolutionService(irodsAccount);
logger.info("dataTypeResolutionService created from factory:{}", dataTypeResolutionService);
logger.info("doing quick check for mime type");
mimeType = dataTypeResolutionService.quickMimeType(path);
logger.info("mimetype:{}", mimeType);
redirectAttributes.addAttribute("path", path);
redirectAttributes.addAttribute("mimeType", mimeType);
return "redirect:/preview/templateByMimeType";
} catch (JargonException e) {
logger.error("Could not retrieve data from path: {}", path, e);
throw new DataGridException(e.getMessage());
} catch (Exception e) {
logger.error("general exception generating preview", e);
throw new DataGridException(e.getLocalizedMessage());
}
} else {
return "collections/preview :: noPermission";
}
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class ServerServiceImpl method getAllNonResourceServers.
@Override
public List<DataGridServer> getAllNonResourceServers(List<DataGridServer> servers, HashMap<String, DataGridServer> serverMapInCache, List<DataGridResource> dataGridResources) throws DataGridConnectionRefusedException {
logger.info("Getting the list of all non-resource servers from the Grid using Resource cache");
List<DataGridServer> nonResourceServers = new ArrayList<DataGridServer>();
for (DataGridServer server : servers) {
if (server.getHostname().compareToIgnoreCase("localhost") == 0) {
continue;
}
ObjectMapper mapper = new ObjectMapper();
String mounts = null;
try {
String serverInfo = getServerInfo(server.getHostname());
JsonNode json = mapper.readTree(serverInfo);
mounts = json.get("mounts").toString();
} catch (JsonProcessingException e) {
logger.error("Could not parse server information", e.getMessage());
} catch (IOException e) {
logger.error("Could not parse server information", e.getMessage());
}
if (mounts != null && !mounts.isEmpty()) {
HashMap<String, String> hashMap = ServerUtil.getNFSMountMap(mounts);
List<DataGridResource> resources = null;
try {
logger.info("Getting resources of a server {}", server.getHostname());
resources = resourceService.getResourcesOfAServer(server.getHostname(), dataGridResources);
} catch (DataGridConnectionRefusedException e) {
// any
if (serverMapInCache != null) {
resources = serverMapInCache.get(server.getHostname()).getResources();
} else {
resources = new ArrayList<DataGridResource>();
}
}
for (DataGridResource resource : resources) {
if (hashMap.containsKey(resource.getPath())) {
String host = hashMap.get(resource.getPath());
DataGridServer newServer = new DataGridServer();
try {
host = reverseDnsLookup.compareTo("true") == 0 ? machineInfoService.getHostName(host) : host;
newServer.setHostname(host);
newServer.setIp(machineInfoService.getAddress(host));
} catch (UnknownHostException e) {
logger.error("Could not resolve IP address for " + host);
}
if (!nonResourceServers.contains(newServer)) {
nonResourceServers.add(newServer);
}
}
}
}
}
return nonResourceServers.isEmpty() ? null : nonResourceServers;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class FilePropertyServiceImpl method findByFileProperties.
@Override
public List<DataGridCollectionAndDataObject> findByFileProperties(List<DataGridFilePropertySearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException, JargonException {
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
List<DataGridCollectionAndDataObject> dataGridObjects = null;
List<DataGridCollectionAndDataObject> dataGridCollections = null;
int totalCollections = 0;
int totalDataObjects = 0;
int startIndex = (pageNum - 1) * pageSize;
int endIndex = (pageNum * pageSize) - 1;
int endIndexForDataObjs;
int endIndexForCollections;
try {
String zone = irodsServices.getCurrentUserZone();
totalCollections = specQueryService.countCollectionsMatchingFileProperties(searchList, zone);
totalDataObjects = specQueryService.countDataObjectsMatchingFileProperties(searchList, zone);
pageContext.setStartItemNumber(startIndex + 1);
pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
if (endIndex + 1 <= totalCollections) {
// looking for collections
SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
endIndexForCollections = dataGridCollections.size();
dataGridCollectionAndDataObjects.addAll(dataGridCollections);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForCollections - 1);
} else if (startIndex + 1 > totalCollections) {
// looking for data objects
SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
dataGridCollectionAndDataObjects.addAll(dataGridObjects);
} else {
// looking for collections
SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
endIndexForDataObjs = pageSize - (totalCollections % pageSize);
// looking for data objects
SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
dataGridCollectionAndDataObjects.addAll(dataGridCollections);
dataGridCollectionAndDataObjects.addAll(dataGridObjects);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
}
} catch (JargonException | UnsupportedDataGridFeatureException e) {
logger.error("Could not find data objects by metadata. ", e);
if (e.getCause() instanceof ConnectException) {
throw new DataGridConnectionRefusedException();
}
}
this.populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
return dataGridCollectionAndDataObjects;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class PermissionsServiceImpl method canLoggedUserModifyPermissionOnPath.
@Override
public boolean canLoggedUserModifyPermissionOnPath(String path) throws DataGridConnectionRefusedException {
String userName = irodsServices.getCurrentUser();
final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
try {
int resultingPermission;
final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(path);
if (irodsFileSystemAO.isDirectory(fileObj)) {
resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, userName);
} else {
resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, userName);
}
return resultingPermission > FilePermissionEnum.WRITE.getPermissionNumericValue();
} catch (final Exception e) {
logger.error("Could not get permissions for current user: {}", e.getMessage());
}
return false;
}
Aggregations