use of gov.usgs.cida.coastalhazards.model.SessionItem in project coastal-hazards by USGS-CIDA.
the class SessionManager method removeItemFromSessions.
public synchronized boolean removeItemFromSessions(String itemId) {
EntityTransaction transaction = em.getTransaction();
for (String sessionId : getSessionIdsByItemId(itemId)) {
try {
Session sessionObj = loadSession(sessionId);
List<SessionItem> newItems = new ArrayList<>(sessionObj.getItems());
for (SessionItem item : sessionObj.getItems()) {
if (item.getItemId().equals(itemId)) {
newItems.remove(item);
}
}
transaction.begin();
em.remove(sessionObj);
sessionObj.setItems(newItems);
em.persist(sessionObj);
transaction.commit();
} catch (Exception ex) {
if (transaction.isActive()) {
transaction.rollback();
}
log.error("An error occurred while modifying the session. Error: " + ex.getMessage());
return false;
}
}
return true;
}
use of gov.usgs.cida.coastalhazards.model.SessionItem in project coastal-hazards by USGS-CIDA.
the class DownloadUtility method stageSessionDownload.
/**
* TODO stage all the items with some smarts about naming and such
*
* @param stageThis
* @param stagingDir
* @return
* @throws java.io.IOException
*/
public static boolean stageSessionDownload(Session stageThis, File stagingDir) throws IOException, ConcurrentModificationException {
boolean success = false;
lock(stagingDir);
List<String> missing = new LinkedList<>();
try {
Map<WFSService, SingleDownload> downloadMap = new HashMap<>(stageThis.getItems().size());
for (SessionItem sessionItem : stageThis.getItems()) {
Item item;
try (ItemManager itemManager = new ItemManager()) {
item = itemManager.load(sessionItem.getItemId());
}
populateDownloadMap(downloadMap, item);
}
List<String> namesUsed = new ArrayList<>(downloadMap.size());
for (SingleDownload stagedDownload : downloadMap.values()) {
while (namesUsed.contains(stagedDownload.getName())) {
stagedDownload.incrementName();
}
namesUsed.add(stagedDownload.getName());
// TODO try/catch this to isolate/retry problem downloads?
boolean stage = stagedDownload.stage(stagingDir, missing);
success = success || stage;
}
} finally {
writeMissingFile(stagingDir, missing);
writeReadmeFile(stagingDir);
unlock(stagingDir);
}
return success;
}
Aggregations