List of usage examples for org.apache.commons.codec.digest DigestUtils sha256Hex
public static String sha256Hex(String data)
From source file:io.hops.hopsworks.common.user.AuthController.java
/** * Change security question and adds account audit for the operation. * * @param user/*from ww w . java 2 s . c o m*/ * @param securityQuestion * @param securityAnswer * @param req */ public void changeSecQA(Users user, String securityQuestion, String securityAnswer, HttpServletRequest req) { user.setSecurityQuestion(SecurityQuestion.getQuestion(securityQuestion)); user.setSecurityAnswer(DigestUtils.sha256Hex(securityAnswer.toLowerCase())); userFacade.update(user); accountAuditFacade.registerAccountChange(user, AccountsAuditActions.SECQUESTION.name(), AccountsAuditActions.SUCCESS.name(), "Changed Security Question.", user, req); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindFormLog03().//from ww w. ja v a2s . c om * user doesn't belong to Folder, but admin */ @Transactional @Test public void testFindForm03() { // given UUID folder = UUID.randomUUID(); UUID formId = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + formId); User user = new User("", "", UserStatus.ACTIVE, UserRole.ROLE_ADMIN); user.setClientid("clientid"); this.userDao.saveUser(user); Asset asset = createAsset("test"); FolderForm form = new FolderForm(); form.setType(ClientFormType.FORM); form.setType(ClientFormType.FORM); form.setFolderid(folder); form.setUUID(formId); form.setSha1hash("FFFF"); form.setAssetid(asset.getAssetId()); form.setData(JSON); form.setInsertedDate(new Date()); form.setUpdatedDate(new Date()); form.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, form, sha256hash); FolderAccess access = new FolderAccess(); access.setStatus(FolderStatus.ACTIVE); access.setFolderid(UUID.randomUUID()); access.setUserid(user.getUserid()); access.setPermissions(FolderPermission.PERM_FORM_ADMIN.name()); this.folderDao.saveFolderAccess(access); getEntityManager().flush(); // when FolderForm result = this.folderDao.findForm(user, folder.toString(), formId.toString()).getLeft(); // then assertEquals(form, result); }
From source file:com.bloatit.model.Member.java
public String getActivationKey() { final DaoMember m = getDao(); final String digest = "" + m.getId() + m.getEmail() + m.getFullname() + m.getPassword() + m.getSalt() + ACTIVATE_SALT;//from w w w .j ava 2s.c o m return DigestUtils.sha256Hex(digest); }
From source file:alfio.controller.ReservationFlowIntegrationTest.java
/** * Test a complete offline payment flow. * Will not check in detail...//from ww w. j av a 2 s .co m */ @Test public void reservationFlowTest() throws Exception { String eventName = event.getShortName(); assertTrue(checkInManager.findAllFullTicketInfo(event.getId()).isEmpty()); List<EventStatistic> eventStatistic = eventStatisticsManager.getAllEventsWithStatistics(user); assertEquals(1, eventStatistic.size()); assertTrue(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo.getNotSoldTickets()); assertEquals(0, eventWithAdditionalInfo.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo.getAvailableSeats()); eventManager.toggleActiveFlag(event.getId(), user, true); // list events String eventList = eventController.listEvents(new BindingAwareModelMap(), Locale.ENGLISH); if (eventManager.getPublishedEvents().size() == 1) { Assert.assertTrue(eventList.startsWith("redirect:/")); } else { assertEquals("/event/event-list", eventList); } // // show event String showEvent = eventController.showEvent(eventName, new BindingAwareModelMap(), new MockHttpServletRequest(), Locale.ENGLISH); assertEquals("/event/show-event", showEvent); // // check calendar checkCalendar(eventName); // String redirectResult = reserveTicket(eventName); String redirectStart = "redirect:/event/" + eventName + "/reservation/"; // check reservation success Assert.assertTrue(redirectResult.startsWith(redirectStart)); Assert.assertTrue(redirectResult.endsWith("/book")); // String reservationIdentifier = redirectResult.substring(redirectStart.length()).replace("/book", ""); // check that the payment page is shown String reservationPage = reservationController.showPaymentPage(eventName, reservationIdentifier, null, null, null, null, null, null, null, null, null, null, null, new BindingAwareModelMap(), Locale.ENGLISH); assertEquals("/event/reservation-page", reservationPage); // // pay offline String successPage = payOffline(eventName, reservationIdentifier); assertEquals("redirect:/event/" + eventName + "/reservation/" + reservationIdentifier + "/success", successPage); // //go to success page, payment is still pending String confirmationPage = reservationController.showConfirmationPage(eventName, reservationIdentifier, false, false, new BindingAwareModelMap(), Locale.ENGLISH, new MockHttpServletRequest()); Assert.assertTrue(confirmationPage.endsWith("/waitingPayment")); assertEquals("/event/reservation-waiting-for-payment", reservationController.showWaitingPaymentPage( eventName, reservationIdentifier, new BindingAwareModelMap(), Locale.ENGLISH)); // validatePayment(eventName, reservationIdentifier); // Assert.assertTrue(reservationController.showWaitingPaymentPage(eventName, reservationIdentifier, new BindingAwareModelMap(), Locale.ENGLISH).endsWith("/success")); // TicketDecorator ticketDecorator = checkReservationComplete(eventName, reservationIdentifier); // String ticketIdentifier = ticketDecorator.getUuid(); //ticket is still not assigned, will redirect Assert.assertTrue(ticketController .showTicket(eventName, ticketIdentifier, false, Locale.ENGLISH, new BindingAwareModelMap()) .startsWith("redirect:/event/")); Assert.assertTrue(ticketController .showTicketForUpdate(eventName, ticketIdentifier, new BindingAwareModelMap(), Locale.ENGLISH) .startsWith("redirect:/event/")); // String fname1 = "Test"; String lname1 = "McTest"; //assign ticket to person assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname1, lname1); assertEquals(1, checkInManager.findAllFullTicketInfo(event.getId()).size()); assertEquals("/event/update-ticket", ticketController.showTicketForUpdate(eventName, ticketIdentifier, new BindingAwareModelMap(), Locale.ENGLISH)); // assertEquals("/event/show-ticket", ticketController.showTicket(eventName, ticketIdentifier, false, Locale.ENGLISH, new BindingAwareModelMap())); // checkCSV(eventName, ticketIdentifier, fname1 + " " + lname1); // use api to update UpdateTicketOwnerForm updateTicketOwnerForm = new UpdateTicketOwnerForm(); updateTicketOwnerForm.setFirstName("Test"); updateTicketOwnerForm.setLastName("Testson"); updateTicketOwnerForm.setEmail("testmctest@test.com"); updateTicketOwnerForm.setUserLanguage("en"); reservationApiController.assignTicketToPerson(eventName, ticketIdentifier, true, updateTicketOwnerForm, new BeanPropertyBindingResult(updateTicketOwnerForm, "updateTicketForm"), new MockHttpServletRequest(), new BindingAwareModelMap(), null); checkCSV(eventName, ticketIdentifier, "Test Testson"); // //update String fname2 = "Test"; String lname2 = "OTest"; assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname2, lname2); checkCSV(eventName, ticketIdentifier, fname2 + " " + lname2); //lock ticket Principal principal = Mockito.mock(Principal.class); Mockito.when(principal.getName()).thenReturn(user); eventApiController.toggleTicketLocking(eventName, ticketDecorator.getCategoryId(), ticketDecorator.getId(), principal); assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname1, fname2); checkCSV(eventName, ticketIdentifier, fname2 + " " + lname2); //ticket has changed, update ticketDecorator = checkReservationComplete(eventName, reservationIdentifier); // check stats after selling one ticket assertFalse(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 2)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo2 = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo2.getNotSoldTickets()); assertEquals(1, eventWithAdditionalInfo2.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo2.getAvailableSeats()); assertEquals(0, eventWithAdditionalInfo2.getCheckedInTickets()); //--- check in sequence String ticketCode = ticketDecorator.ticketCode(event.getPrivateKey()); TicketAndCheckInResult ticketAndCheckInResult = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.OK_READY_TO_BE_CHECKED_IN, ticketAndCheckInResult.getResult().getStatus()); CheckInApiController.TicketCode tc = new CheckInApiController.TicketCode(); tc.setCode(ticketCode); assertEquals(CheckInStatus.SUCCESS, checkInApiController .checkIn(event.getId(), ticketIdentifier, tc, new TestingAuthenticationToken("ciccio", "ciccio")) .getResult().getStatus()); List<ScanAudit> audits = scanAuditRepository.findAllForEvent(event.getId()); assertFalse(audits.isEmpty()); assertTrue(audits.stream().anyMatch(sa -> sa.getTicketUuid().equals(ticketIdentifier))); TicketAndCheckInResult ticketAndCheckInResultOk = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.ALREADY_CHECK_IN, ticketAndCheckInResultOk.getResult().getStatus()); // check stats after check in one ticket assertFalse(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo3 = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo3.getNotSoldTickets()); assertEquals(0, eventWithAdditionalInfo3.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo3.getAvailableSeats()); assertEquals(1, eventWithAdditionalInfo3.getCheckedInTickets()); //test revert check in assertTrue(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal)); assertFalse(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal)); TicketAndCheckInResult ticketAndCheckInResult2 = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.OK_READY_TO_BE_CHECKED_IN, ticketAndCheckInResult2.getResult().getStatus()); UsersApiController.UserWithPasswordAndQRCode sponsorUser = usersApiController .insertUser(new UserModification(null, event.getOrganizationId(), "SPONSOR", "sponsor", "first", "last", "email@email.com"), "http://localhost:8080", principal); Principal sponsorPrincipal = Mockito.mock(Principal.class); Mockito.when(sponsorPrincipal.getName()).thenReturn(sponsorUser.getUsername()); // check failures assertEquals(CheckInStatus.EVENT_NOT_FOUND, attendeeApiController.scanBadge( new AttendeeApiController.SponsorScanRequest("not-existing-event", "not-existing-ticket"), sponsorPrincipal).getBody().getResult().getStatus()); assertEquals(CheckInStatus.TICKET_NOT_FOUND, attendeeApiController .scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, "not-existing-ticket"), sponsorPrincipal) .getBody().getResult().getStatus()); assertEquals(CheckInStatus.INVALID_TICKET_STATE, attendeeApiController .scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, ticketIdentifier), sponsorPrincipal) .getBody().getResult().getStatus()); // // check stats after revert check in one ticket assertFalse(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo4 = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo4.getNotSoldTickets()); assertEquals(1, eventWithAdditionalInfo4.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo4.getAvailableSeats()); assertEquals(0, eventWithAdditionalInfo4.getCheckedInTickets()); CheckInApiController.TicketCode tc2 = new CheckInApiController.TicketCode(); tc2.setCode(ticketCode); TicketAndCheckInResult ticketAndcheckInResult = checkInApiController.checkIn(event.getId(), ticketIdentifier, tc2, new TestingAuthenticationToken("ciccio", "ciccio")); assertEquals(CheckInStatus.SUCCESS, ticketAndcheckInResult.getResult().getStatus()); // // List<Integer> offlineIdentifiers = checkInApiController.getOfflineIdentifiers(event.getShortName(), 0L, new MockHttpServletResponse(), principal); assertTrue(offlineIdentifiers.isEmpty()); configurationRepository.insertEventLevel(event.getOrganizationId(), event.getId(), ConfigurationKeys.OFFLINE_CHECKIN_ENABLED.name(), "true", null); configurationRepository.insert(ConfigurationKeys.ALFIO_PI_INTEGRATION_ENABLED.name(), "true", null); offlineIdentifiers = checkInApiController.getOfflineIdentifiers(event.getShortName(), 0L, new MockHttpServletResponse(), principal); assertFalse(offlineIdentifiers.isEmpty()); Map<String, String> payload = checkInApiController.getOfflineEncryptedInfo(event.getShortName(), Collections.emptyList(), offlineIdentifiers, principal); assertEquals(1, payload.size()); Ticket ticket = ticketAndcheckInResult.getTicket(); String ticketKey = ticket.hmacTicketInfo(event.getPrivateKey()); String hashedTicketKey = DigestUtils.sha256Hex(ticketKey); String encJson = payload.get(hashedTicketKey); assertNotNull(encJson); String ticketPayload = CheckInManager.decrypt(ticket.getUuid() + "/" + ticketKey, encJson); Map<String, String> jsonPayload = Json.fromJson(ticketPayload, new TypeReference<Map<String, String>>() { }); assertNotNull(jsonPayload); assertEquals(8, jsonPayload.size()); assertEquals("Test", jsonPayload.get("firstName")); assertEquals("OTest", jsonPayload.get("lastName")); assertEquals("Test OTest", jsonPayload.get("fullName")); assertEquals(ticket.getUuid(), jsonPayload.get("uuid")); assertEquals("testmctest@test.com", jsonPayload.get("email")); assertEquals("CHECKED_IN", jsonPayload.get("status")); String categoryName = ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst() .orElseThrow(IllegalStateException::new).getName(); assertEquals(categoryName, jsonPayload.get("category")); // // check register sponsor scan success flow assertTrue(attendeeApiController.getScannedBadges(event.getShortName(), EventUtil.JSON_DATETIME_FORMATTER.format(LocalDateTime.of(1970, 1, 1, 0, 0)), sponsorPrincipal) .getBody().isEmpty()); assertEquals(CheckInStatus.SUCCESS, attendeeApiController .scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, ticket.getUuid()), sponsorPrincipal) .getBody().getResult().getStatus()); assertEquals(1, attendeeApiController.getScannedBadges(event.getShortName(), EventUtil.JSON_DATETIME_FORMATTER.format(LocalDateTime.of(1970, 1, 1, 0, 0)), sponsorPrincipal).getBody().size()); // eventManager.deleteEvent(event.getId(), principal.getName()); }
From source file:com.bloatit.model.Member.java
public String getEmailActivationKey() { final DaoMember m = getDao(); final String digest = "" + m.getId() + m.getEmail() + m.getEmailToActivate() + m.getFullname() + m.getPassword() + m.getSalt() + ACTIVATE_SALT; return DigestUtils.sha256Hex(digest); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindForms01()./* ww w . j av a 2s .c o m*/ * @throws IOException IOException */ @Transactional @Test public void testFindForms01() throws IOException { // given User user = createUser("AAA", UserRole.ROLE_USER); UUID folder = UUID.randomUUID(); String token = null; UUID formId = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + formId); FolderFormsSearchCriteria criteria = new FolderFormsSearchCriteria(); criteria.setOrderby(FormOrderByField.NAME); criteria.setSorter(SortDirection.ASC); criteria.setStatus(Arrays.asList(FolderFormStatus.ACTIVE)); byte[] bytes = Resources.getResourceAsBytes("/test_form.fkz"); String data = getJSONFromZip(bytes); Asset asset = createAsset("test"); FolderForm form = new FolderForm(); form.setType(ClientFormType.FORM); form.setFolderid(folder); form.setUUID(formId); form.setSha1hash("FFFF"); form.setAssetid(asset.getAssetId()); form.setData(data); form.setInsertedDate(new Date()); form.setUpdatedDate(new Date()); form.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, form, sha256hash); getEntityManager().flush(); // when FolderFormsListDTO result = this.folderDao.findForms(folder.toString(), null, criteria, token); // then assertEquals(1, result.getForms().size()); assertEquals("test 1", result.getForms().get(0).getName()); assertEquals("E0F799E5-B291-4994-8F11-609A7F72612E", result.getForms().get(0).getUUID()); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindForms02()./*from w w w. j a va 2 s . com*/ * with parent * @throws IOException IOException */ @Transactional @Test public void testFindForms02() throws IOException { // given User user = createUser("AAA", UserRole.ROLE_USER); FolderFormsSearchCriteria criteria = new FolderFormsSearchCriteria(); criteria.setOrderby(FormOrderByField.NAME); criteria.setSorter(SortDirection.ASC); criteria.setStatus(Arrays.asList(FolderFormStatus.ACTIVE)); String token = null; UUID formId = UUID.randomUUID(); UUID folder = UUID.randomUUID(); String sha256hash = DigestUtils.sha256Hex(folder + " " + formId); byte[] bytes = Resources.getResourceAsBytes("/test_form.fkz"); String data = getJSONFromZip(bytes); Asset asset = createAsset("test"); FolderForm form = new FolderForm(); form.setType(ClientFormType.FORM); form.setFolderid(folder); form.setUUID(formId); form.setSha1hash("FFFF"); form.setInsertedDate(new Date()); form.setUpdatedDate(new Date()); form.setParentUUID(UUID.randomUUID()); form.setAssetid(asset.getAssetId()); form.setData(data); form.setStatus(FolderFormStatus.ACTIVE); this.folderDao.saveForm(user, form, sha256hash); getEntityManager().flush(); // when FolderFormsListDTO result = this.folderDao.findForms(folder.toString(), null, criteria, token); // then assertEquals(0, result.getForms().size()); }
From source file:com.bloatit.model.Member.java
public String getResetKey() { final DaoMember m = getDao(); final String digest = "" + m.getId() + m.getEmail() + m.getFullname() + m.getPassword() + m.getSalt() + RESET_SALT;/*from www.j av a 2 s . c o m*/ return DigestUtils.sha256Hex(digest); }
From source file:com.formkiq.core.dao.FolderDaoImplTest.java
/** * testFindForms03().// w w w .j a v a 2 s .c o m * @throws IOException IOException */ @Transactional @Test public void testFindForms03() throws IOException { // given User user = createUser("AAA", UserRole.ROLE_USER); FolderFormsSearchCriteria criteria = new FolderFormsSearchCriteria(); criteria.setOrderby(FormOrderByField.NAME); criteria.setSorter(SortDirection.ASC); criteria.setStatus(Arrays.asList(FolderFormStatus.ACTIVE)); String token = null; UUID folder = UUID.randomUUID(); final int max = 10; final int formCount = 13; Asset asset = createAsset("test"); String sha256hash = DigestUtils.sha256Hex(folder + " "); for (int i = 0; i < formCount; i++) { FolderForm form = new FolderForm(); form.setFolderid(folder); form.setType(ClientFormType.FORM); form.setStatus(FolderFormStatus.ACTIVE); form.setUUID(UUID.randomUUID()); form.setInsertedDate(new Date()); form.setUpdatedDate(new Date()); form.setSha1hash("uuid" + String.format("%02d", Integer.valueOf(i))); form.setAssetid(asset.getAssetId()); form.setData("{\"name\":\"uuid" + String.format("%02d", Integer.valueOf(i)) + "\",\"uuid\":\"uuid" + String.format("%02d", Integer.valueOf(i)) + "\"}"); this.folderDao.saveForm(user, form, sha256hash); } getEntityManager().flush(); // when FolderFormsListDTO result = this.folderDao.findForms(folder.toString(), null, criteria, token); // then assertEquals("MTA6MTA=", result.getNexttoken()); assertNull(result.getPrevtoken()); int i = 0; List<FormDTO> forms = result.getForms(); assertEquals(max, forms.size()); assertEquals("uuid00", forms.get(i++).getSha1hash()); assertEquals("uuid01", forms.get(i++).getSha1hash()); assertEquals("uuid02", forms.get(i++).getSha1hash()); assertEquals("uuid03", forms.get(i++).getSha1hash()); assertEquals("uuid04", forms.get(i++).getSha1hash()); assertEquals("uuid05", forms.get(i++).getSha1hash()); assertEquals("uuid06", forms.get(i++).getSha1hash()); assertEquals("uuid07", forms.get(i++).getSha1hash()); assertEquals("uuid08", forms.get(i++).getSha1hash()); assertEquals("uuid09", forms.get(i++).getSha1hash()); // when result = this.folderDao.findForms(folder.toString(), null, criteria, result.getNexttoken()); // then assertNull(result.getNexttoken()); assertEquals("MDoxMA==", result.getPrevtoken()); final int max1 = 3; i = 0; forms = result.getForms(); assertEquals(max1, forms.size()); assertEquals("uuid10", forms.get(i++).getSha1hash()); assertEquals("uuid11", forms.get(i++).getSha1hash()); assertEquals("uuid12", forms.get(i++).getSha1hash()); // when result = this.folderDao.findForms(folder.toString(), null, criteria, result.getPrevtoken()); // then i = 0; forms = result.getForms(); assertEquals("MTA6MTA=", result.getNexttoken()); assertNull(result.getPrevtoken()); assertEquals(max, forms.size()); assertEquals("uuid00", forms.get(i++).getSha1hash()); assertEquals("uuid01", forms.get(i++).getSha1hash()); assertEquals("uuid02", forms.get(i++).getSha1hash()); assertEquals("uuid03", forms.get(i++).getSha1hash()); assertEquals("uuid04", forms.get(i++).getSha1hash()); assertEquals("uuid05", forms.get(i++).getSha1hash()); assertEquals("uuid06", forms.get(i++).getSha1hash()); assertEquals("uuid07", forms.get(i++).getSha1hash()); assertEquals("uuid08", forms.get(i++).getSha1hash()); assertEquals("uuid09", forms.get(i++).getSha1hash()); }
From source file:io.hops.hopsworks.apiV2.projects.DatasetsResource.java
private Response unzip(Dataset dataset, String targetPath, SecurityContext sc) throws AppException, AccessControlException { DatasetPath dsPath = new DatasetPath(dataset, targetPath); org.apache.hadoop.fs.Path fullPath = pathValidator.getFullPath(dsPath); String localDir = DigestUtils.sha256Hex(fullPath.toString()); String stagingDir = settings.getStagingDir() + File.separator + localDir; File unzipDir = new File(stagingDir); unzipDir.mkdirs();//from www . j av a2s. c o m settings.addUnzippingState(fullPath.toString()); // HDFS_USERNAME is the next param to the bash script Users user = userFacade.findByEmail(sc.getUserPrincipal().getName()); String hdfsUser = hdfsUsersBean.getHdfsUserName(project, user); List<String> commands = new ArrayList<>(); commands.add(settings.getHopsworksDomainDir() + "/bin/unzip-background.sh"); commands.add(stagingDir); commands.add(fullPath.toString()); commands.add(hdfsUser); SystemCommandExecutor commandExecutor = new SystemCommandExecutor(commands, false); String stdout = "", stderr = ""; try { int result = commandExecutor.executeCommand(); stdout = commandExecutor.getStandardOutputFromCommand(); stderr = commandExecutor.getStandardErrorFromCommand(); if (result == 2) { throw new AppException(Response.Status.EXPECTATION_FAILED.getStatusCode(), "Not enough free space on the local scratch directory to download and unzip this file." + "Talk to your admin to increase disk space at the path: hopsworks/staging_dir"); } if (result != 0) { throw new AppException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Could not unzip the file at path: " + fullPath); } } catch (InterruptedException e) { logger.log(Level.FINE, null, e); throw new AppException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Interrupted exception. Could not unzip the file at path: " + fullPath); } catch (IOException ex) { logger.log(Level.FINE, null, ex); throw new AppException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "IOException. Could not unzip the file at path: " + fullPath); } return Response.noContent().build(); }