List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:org.ednovo.gooru.domain.service.classplan.LearnguideServiceImpl.java
@Override public String updateCollectionThumbnail(String gooruContentId, String fileName, String imageURL, Map<String, Object> formField) throws Exception { boolean isHasSlash = StringUtils.contains(fileName, '\\'); if (isHasSlash) { fileName = StringUtils.substringAfterLast(fileName, Character.toString('\\')); }/*from w w w . j a v a 2 s.c om*/ Learnguide collection = this.getLearnguideRepository().findByContent(gooruContentId); boolean buildThumbnail = false; if (imageURL != null && imageURL.length() > 0) { String resourceImageFile = collection.getOrganization().getNfsStorageArea().getInternalPath() + collection.getFolder() + "/" + fileName; String prevFileName = collection.getThumbnail(); if (prevFileName != null && !prevFileName.equalsIgnoreCase("")) { File prevFile = new File(collection.getOrganization().getNfsStorageArea().getInternalPath() + collection.getFolder() + "/" + prevFileName); if (prevFile.exists()) { prevFile.delete(); } s3ResourceApiHandler.deleteResourceFile(collection, collection.getThumbnail()); } ImageUtil.downloadAndSaveFile(imageURL, resourceImageFile); collection.setThumbnail(fileName); buildThumbnail = true; logger.info("Thumbnail downloader:Resource " + collection.getGooruOid() + " didn't have image. downloading into " + resourceImageFile); } else { File classplanDir = new File( collection.getOrganization().getNfsStorageArea().getInternalPath() + collection.getFolder()); if (!classplanDir.exists()) { classplanDir.mkdirs(); } Map<String, byte[]> files = (Map<String, byte[]>) formField.get(RequestUtil.UPLOADED_FILE_KEY); byte[] fileData = null; // expecting only one file in the request right now for (byte[] fileContent : files.values()) { fileData = fileContent; } if (fileData != null && fileData.length > 0) { String prevFileName = collection.getThumbnail(); if (prevFileName != null && !prevFileName.equalsIgnoreCase("")) { File prevFile = new File(collection.getOrganization().getNfsStorageArea().getInternalPath() + collection.getFolder() + "/" + prevFileName); if (prevFile.exists()) { prevFile.delete(); } } File file = new File(collection.getOrganization().getNfsStorageArea().getInternalPath() + collection.getFolder() + "/" + fileName); OutputStream out = new FileOutputStream(file); out.write(fileData); out.close(); collection.setThumbnail(fileName); buildThumbnail = true; } } this.getLearnguideRepository().save(collection); if (buildThumbnail) { resourceImageUtil.sendMsgToGenerateThumbnails(collection); } indexProcessor.index(collection.getGooruOid(), IndexProcessor.INDEX, COLLECTION); // Remove the collection from cache collectionUtil.deleteCollectionFromCache(gooruContentId, COLLECTION); return collection.getFolder() + "/" + fileName; }
From source file:org.ednovo.gooru.domain.service.collection.ResourceBoServiceImpl.java
@Override public Resource createResource(Resource newResource, User user) { Resource resource = null;// w ww . j a v a 2s .c o m if (newResource.getUrl() != null && !newResource.getUrl().isEmpty() && newResource.getAttach() == null) { resource = this.getResourceRepository().findResourceByUrl(newResource.getUrl(), Sharing.PUBLIC.getSharing(), null); } if (this.getOperationAuthorizer().hasUnrestrictedContentAccess() && resource != null && resource.getSharing() != null && resource.getSharing().equalsIgnoreCase(Sharing.PUBLIC.getSharing())) { throw new AccessDeniedException(generateErrorMessage(GL0012)); } final String title = newResource.getTitle().length() > 1000 ? newResource.getTitle().substring(0, 1000) : newResource.getTitle(); if (resource == null) { resource = new Resource(); resource.setGooruOid(UUID.randomUUID().toString()); resource.setUser(user); resource.setTitle(title); if (newResource.getResourceFormat() != null) { CustomTableValue resourcetype = this.getCustomTableRepository() .getCustomTableValue(RESOURCE_CATEGORY_FORMAT, newResource.getResourceFormat().getValue()); resource.setResourceFormat(resourcetype); } resource.setDescription(newResource.getDescription()); License license = new License(); license.setName(OTHER); if (resource.getRecordSource() == null) { resource.setRecordSource(Resource.RecordSource.COLLECTION.getRecordSource()); } final ResourceType resourceTypeDo = new ResourceType(); resource.setResourceType(resourceTypeDo); String fileExtension = null; if (newResource.getAttach() != null && newResource.getAttach().getFilename() != null) { fileExtension = StringUtils.substringAfterLast(newResource.getAttach().getFilename(), "."); if (fileExtension.contains(PDF) || BaseUtil.supportedDocument().containsKey(fileExtension)) { resourceTypeDo.setName(ResourceType.Type.HANDOUTS.getType()); } else { resourceTypeDo.setName(ResourceType.Type.IMAGE.getType()); } resource.setUrl(newResource.getAttach().getFilename()); resource.setIsOer(1); license.setName(CREATIVE_COMMONS); } else { resource.setUrl(newResource.getUrl()); if (ResourceImageUtil.getYoutubeVideoId(newResource.getUrl()) != null) { resourceTypeDo.setName(ResourceType.Type.VIDEO.getType()); } else if (newResource.getUrl() != null && newResource.getUrl().contains("vimeo.com")) { final String id = StringUtils.substringAfterLast(newResource.getUrl(), "/"); if (StringUtils.isNumeric(id)) { resource.setHasFrameBreaker(true); final ResourceMetadataCo resourceMetadataCo = ResourceImageUtil .getMetaDataFromVimeoVideo(newResource.getUrl()); resourceTypeDo.setName(ResourceType.Type.VIMEO_VIDEO.getType()); newResource.setThumbnail( resourceMetadataCo != null ? resourceMetadataCo.getThumbnail() : null); } else { resourceTypeDo.setName(ResourceType.Type.RESOURCE.getType()); } } else { resourceTypeDo.setName(ResourceType.Type.RESOURCE.getType()); } } resource.setLicense(license); if (newResource.getSharing() != null) { resource.setSharing(Sharing.PRIVATE.getSharing()); } else { resource.setSharing(newResource.getSharing()); } String domainName = BaseUtil.getDomainName(newResource.getUrl()); ResourceSource resourceSource = null; if (domainName != null) { resourceSource = this.getResourceRepository().findResourceSource(domainName); } if (resourceSource != null && resourceSource.getFrameBreaker() != null && resourceSource.getFrameBreaker() == 1) { resource.setHasFrameBreaker(true); } else if ((newResource.getUrl() != null && newResource.getUrl().contains(YOUTUBE_URL) && ResourceImageUtil.getYoutubeVideoId(newResource.getUrl()) == null)) { resource.setHasFrameBreaker(true); } else { resource.setHasFrameBreaker(false); } getResourceRepository().saveOrUpdate(resource); updateYoutubeResourceFeeds(resource, false); getResourceRepository().save(resource); mapSourceToResource(resource); if (newResource.getHost() != null && newResource.getHost().size() > 0) { resource.setHost(updateContentProvider(resource.getGooruOid(), newResource.getHost(), user, HOST)); } try { if (newResource.getThumbnail() != null || fileExtension != null && fileExtension.contains(PDF)) { this.getResourceImageUtil().downloadAndSendMsgToGenerateThumbnails(resource, newResource.getThumbnail()); } } catch (Exception e) { LOGGER.error(_ERROR, e); } if (resource != null) { getIndexHandler().setReIndexRequest(resource.getGooruOid(), IndexProcessor.INDEX, RESOURCE, null, false, false); } if (newResource.getAttach() != null) { this.getResourceImageUtil().moveAttachment(newResource, resource); } } return resource; }
From source file:org.ednovo.gooru.domain.service.CollectionServiceImpl.java
private ActionResponseDTO<CollectionItem> updateQuestionWithCollectionItem(final CollectionItem collectionItem, final String data, final List<Integer> deleteAssets, final User user, final String mediaFileName) throws Exception { final AssessmentQuestion newQuestion = getAssessmentService().buildQuestionFromInputParameters(data, user, true);//from ww w . j a v a 2 s .com final Errors errors = validateUpdateCollectionItem(collectionItem); if (!errors.hasErrors()) { final AssessmentQuestion question = getAssessmentService() .getQuestion(collectionItem.getContent().getGooruOid()); if (question != null) { AssessmentQuestion assessmentQuestion = assessmentService .updateQuestion(newQuestion, deleteAssets, question.getGooruOid(), true, true).getModel(); this.getResourceService().saveOrUpdateResourceTaxonomy(assessmentQuestion, newQuestion.getTaxonomySet()); if (assessmentQuestion != null) { if (mediaFileName != null && mediaFileName.length() > 0) { String questionImage = this.assessmentService.updateQuizQuestionImage( assessmentQuestion.getGooruOid(), mediaFileName, question, ASSET_QUESTION); if (questionImage != null && questionImage.length() > 0) { if (ResourceImageUtil.getYoutubeVideoId(questionImage) != null || questionImage.contains(YOUTUBE_URL)) { assessmentQuestion = this.assessmentService .updateQuestionVideoAssest(assessmentQuestion.getGooruOid(), questionImage); } else { assessmentQuestion = this.assessmentService.updateQuestionAssest( assessmentQuestion.getGooruOid(), StringUtils.substringAfterLast(questionImage, "/")); } } } if (assessmentQuestion.isQuestionNewGen()) { List<String> mediaFilesToAdd = newQuestion.getMediaFiles(); if (mediaFilesToAdd != null && mediaFilesToAdd.size() > 0) { for (String mediaFileToAdd : mediaFilesToAdd) { assessmentService.updateQuizQuestionImage(assessmentQuestion.getGooruOid(), mediaFileToAdd, assessmentQuestion, null); } } } // collectionItem.setQuestionInfo(assessmentQuestion); collectionItem .setStandards(this.getStandards(assessmentQuestion.getTaxonomySet(), false, null)); } // Update the question in mongo now that transaction is almost // done mongoQuestionsService.updateQuestion(collectionItem.getContent().getGooruOid(), data); getAsyncExecutor().deleteFromCache( V2_ORGANIZE_DATA + collectionItem.getCollection().getUser().getPartyUid() + "*"); } } else { throw new NotFoundException(generateErrorMessage(GL0056, QUESTION), GL0056); } return new ActionResponseDTO<CollectionItem>(collectionItem, errors); }
From source file:org.ednovo.gooru.domain.service.resource.impl.MediaServiceImpl.java
@Override public FileMeta handleFileUpload(MediaDTO mediaDTO, Map<String, Object> formField) throws FileNotFoundException, IOException { String fileExtension = null;/*from w w w.j a v a 2 s . co m*/ if (formField.get(RequestUtil.UPLOADED_FILE_KEY) != null) { @SuppressWarnings("unchecked") Map<String, byte[]> files = (Map<String, byte[]>) formField.get(RequestUtil.UPLOADED_FILE_KEY); for (String name : files.keySet()) { if (name != null) { fileExtension = StringUtils.substringAfterLast(name, "."); break; } } } if (fileExtension == null || fileExtension.isEmpty()) { fileExtension = PNG; } Map<String, String> fileExtentions = BaseUtil.supportedDocument(); if (fileExtentions.containsKey(fileExtension)) { mediaDTO.setResize(false); } if (fileExtension != null && (fileExtension.equalsIgnoreCase(PDF)) || fileExtension != null && fileExtentions != null) { mediaDTO.setResize(false); } mediaDTO.setFilename(UUID.randomUUID().toString() + "." + fileExtension); return handleFileUpload(mediaDTO.getFilename(), mediaDTO.getImageURL(), formField, mediaDTO.getResize(), mediaDTO.getWidth(), mediaDTO.getHeight()); }
From source file:org.ednovo.gooru.domain.service.resource.ResourceServiceImpl.java
@Override public void saveNewResource(final Resource resource, final boolean downloadResource) throws IOException { resource.setCreatedOn(new Date(System.currentTimeMillis())); if (StringUtils.isEmpty(resource.getGooruOid())) { resource.setGooruOid(UUID.randomUUID().toString()); }// www . j ava 2s .c o m resource.setLastModified(resource.getCreatedOn()); this.getResourceRepository().saveOrUpdate(resource); if (downloadResource) { final String sourceUrl = resource.getUrl(); final String fileName = StringUtils.substringAfterLast(sourceUrl, "/"); final File resourceFolder = new File( resource.getOrganization().getNfsStorageArea().getInternalPath() + resource.getFolder()); if (!resourceFolder.exists()) { resourceFolder.mkdir(); } final String resourceFilePath = resource.getOrganization().getNfsStorageArea().getInternalPath() + resource.getFolder() + File.separator + fileName; final boolean downloaded = ImageUtil.downloadAndSaveFile(sourceUrl, resourceFilePath); if (!downloaded) { throw new IOException(generateErrorMessage("GL0093", resource.getUrl())); } this.getAsyncExecutor().uploadResourceFolder(resource); resource.setUrl(fileName); this.getResourceRepository().saveOrUpdate(resource); if (fileName.toLowerCase().endsWith(DOT_PDF)) { final Map<String, Object> param = new HashMap<String, Object>(); param.put(RESOURCE_FILE_PATH, resourceFilePath); param.put(RESOURCE_GOORU_OID, resource.getGooruOid()); RequestUtil .executeRestAPI(param, settingService.getConfigSetting(ConfigConstants.GOORU_CONVERSION_RESTPOINT, 0, TaxonomyUtil.GOORU_ORG_UID) + "/conversion/pdf-to-image", Method.POST.getName()); } } else { // Save resource folder resourceRepository.saveOrUpdate(resource); } }
From source file:org.ednovo.gooru.domain.service.resource.ResourceServiceImpl.java
@Override public Resource handleNewResource(Resource resource, final String resourceTypeForPdf, final String thumbnail) { // test if a resource with url exist, currently just skip. Errors errors = new BindException(Resource.class, RESOURCE); Resource updatedResource = updateResource(resource, true, thumbnail, errors); if (updatedResource != null) { return updatedResource; }//ww w . j a v a2s . c o m errors = new BindException(Resource.class, RESOURCE); boolean downloadedFlag = false; // download if need and save: // FIXME /* * downloadedFlag = downloadFileIfRequiredAndUpdateUrl(resource, * StringUtils.defaultString(resourceTypeForPdf, * ResourceType.Type.HANDOUTS.getType())); */ final ResourceType resourceType = new ResourceType(); resource.setResourceType(resourceType); final String fileExtension = org.apache.commons.lang.StringUtils.substringAfterLast(resource.getUrl(), "."); if (fileExtension.equalsIgnoreCase(PDF) || fileExtension.equalsIgnoreCase(PNG)) { if (fileExtension.contains(PDF)) { resourceType.setName(ResourceType.Type.HANDOUTS.getType()); } else { resourceType.setName(ResourceType.Type.IMAGE.getType()); } } else { resourceType.setName(ResourceImageUtil.getYoutubeVideoId(resource.getUrl()) != null ? ResourceType.Type.VIDEO.getType() : ResourceType.Type.RESOURCE.getType()); } resource = saveResource(resource, errors, false); if (resource == null || errors.hasErrors()) { LOGGER.error("save resource failed" + errors.toString()); } if (downloadedFlag) { // Move the resource to the right folder File resourceFile = new File(resource.getUrl()); if (resourceFile.exists()) { final File resourceFolder = new File( resource.getOrganization().getNfsStorageArea().getInternalPath() + resource.getFolder()); if (!resourceFolder.exists()) { resourceFolder.mkdir(); } final String fileName = StringUtils.substringAfterLast(resource.getUrl(), "/"); resourceFile.renameTo(new File(resourceFolder.getPath(), fileName)); resource.setUrl(fileName); this.getResourceRepository().saveOrUpdate(resource); String resourceFilePath = resource.getOrganization().getNfsStorageArea().getInternalPath() + resource.getFolder() + resource.getUrl(); resourceFilePath = resourceFilePath.trim(); if (fileName.toLowerCase().endsWith(DOT_PDF)) { final Map<String, Object> param = new HashMap<String, Object>(); param.put(RESOURCE_FILE_PATH, resourceFilePath); param.put(RESOURCE_GOORU_OID, resource.getGooruOid()); RequestUtil.executeRestAPI(param, settingService.getConfigSetting(ConfigConstants.GOORU_CONVERSION_RESTPOINT, 0, TaxonomyUtil.GOORU_ORG_UID) + "/conversion/pdf-to-image", Method.POST.getName()); } } } else { // Save resource folder this.getResourceRepository().saveOrUpdate(resource); } enrichAndAddOrUpdate(resource); // if handouts, split and save chapters as resources: if (resource.getResourceType().getName().equalsIgnoreCase(ResourceType.Type.HANDOUTS.getType())) { final List<Resource> chapterResources = splitToChaptersResources(resource); for (final Resource chapterResource : chapterResources) { enrichAndAddOrUpdate(chapterResource); } } indexHandler.setReIndexRequest(resource.getGooruOid(), IndexProcessor.INDEX, RESOURCE, null, false, false); return resource; }
From source file:org.ednovo.gooru.domain.service.segment.SegmentServiceImpl.java
@Override public void updateSegment(String gooruContentId, String segmentId, String title, String duration, String type, String rendition, String description, String concept, String uploadedImageSrc, User user, Learnguide collection) {//from w w w.j a v a2s .c om Segment updateSegment = null; for (Segment segment : collection.getResourceSegments()) { if (segment.getSegmentId().equals(segmentId)) { segment.setDuration(duration); segment.setSegmentId(segmentId); segment.setTitle(title); segment.setType(type); segment.setRenditionUrl(rendition); segment.setDescription(description); /* * segment.setSequence(getResourceService().getResourceSegmentsCount * (gooruContentId) + 1); */ segment.setConcept(concept); updateSegment = segment; break; } } classplanRepository.save(collection); try { revisionHistoryService.createVersion(collection, "SegmentUpdate"); } catch (Exception ex) { ex.printStackTrace(); } if (logger.isInfoEnabled()) { logger.info(LogUtil.getActivityLogStream(COLLECTION, user.toString(), updateSegment.toString(), LogUtil.SEGMENT_EDIT, "")); } indexProcessor.index(collection.getGooruOid(), IndexProcessor.INDEX, "collection"); // Remove the collection from cache collectionUtil.deleteCollectionFromCache(gooruContentId, COLLECTION); if (uploadedImageSrc != null && !uploadedImageSrc.equals("")) { String uploadedMediaFolder = "/" + Constants.UPLOADED_MEDIA_FOLDER + "/"; Segment segment = resourceService.getSegment(segmentId); if (uploadedImageSrc.contains(uploadedMediaFolder) && segment != null) { String folder = collection.getFolder() + Constants.SEGMENT_FOLDER; String repoPath = collection.getOrganization().getNfsStorageArea().getInternalPath(); String fileName = StringUtils.substringAfterLast(uploadedImageSrc, uploadedMediaFolder); String fileExtension = StringUtils.substringAfterLast(uploadedImageSrc, "."); String srcPath = repoPath + folder + "/"; uploadedImageSrc = repoPath + uploadedMediaFolder + fileName; try { uploadedImageSrc = GooruImageUtil.moveImage(uploadedImageSrc, srcPath, segmentId); segment.setSegmentImage(Constants.SEGMENT_FOLDER + "/" + segmentId + "." + fileExtension); segmentRepository.save(segment); logger.error("segment image Source:" + uploadedImageSrc + " destination folder: " + srcPath); Map<String, Object> param = new HashMap<String, Object>(); param.put("sourceFilePath", uploadedImageSrc); param.put("targetFolderPath", srcPath); param.put("dimensions", ResourceImageUtil.RESOURCE_THUMBNAIL_SIZES); param.put("resourceGooruOid", collection.getGooruOid()); param.put("apiEndPoint", settingService.getConfigSetting(ConfigConstants.GOORU_API_ENDPOINT, 0, TaxonomyUtil.GOORU_ORG_UID)); RequestUtil .executeRestAPI(param, settingService.getConfigSetting(ConfigConstants.GOORU_CONVERSION_RESTPOINT, 0, TaxonomyUtil.GOORU_ORG_UID) + "/conversion/image", Method.POST.getName()); } catch (Exception e) { logger.error("uploading image faild: " + e); } } } }
From source file:org.efs.openreports.dispatcher.FileDispatcher.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fileName = ""; try {/*from w w w . ja v a2s . c om*/ fileName = StringUtils.substringAfterLast(request.getRequestURI(), "/"); File file = new File(imageDirectory + fileName); if (!file.exists()) { file = new File(imageTempDirectory + fileName); } if (!file.exists()) { fileName = request.getParameter("fileName"); // report file delivery validates the filename against the username // of the user in session for security purposes. ReportUser user = (ReportUser) request.getSession().getAttribute(ORStatics.REPORT_USER); if (user == null || fileName.indexOf(user.getName()) < 0) { String message = "Not Authorized..."; response.getOutputStream().write(message.getBytes()); return; } file = new File(reportGenerationDirectory + fileName); } byte[] fileDate = FileUtils.readFileToByteArray(file); response.setContentLength(fileDate.length); ServletOutputStream ouputStream = response.getOutputStream(); ouputStream.write(fileDate, 0, fileDate.length); ouputStream.flush(); ouputStream.close(); } catch (Exception e) { log.warn(e); String message = "Error Loading File..."; response.getOutputStream().write(message.getBytes()); } }
From source file:org.entando.edo.model.EdoBuilder.java
public String getProjectName() { String name = StringUtils.substringAfterLast(this.getBaseDir(), File.separator); name = name.replaceAll("_", ""); name = name.replaceAll("-", ""); return StringUtils.uncapitalize(name); }
From source file:org.entando.edo.model.EdoBuilder.java
public String getSpringBeanPreposition() { String name = StringUtils.substringAfterLast(this.getBaseDir(), File.separator); name = name.replaceAll("_", ""); name = name.replaceAll("-", ""); if (isPlugin()) { String pname = StringUtils.substringAfter(this.getPackageName(), ".plugins."); name = pname.split("\\.")[0]; }//w w w .j a v a 2 s . c om return name; }