Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

B.1 Part of the codes for accessing the directory tree resource management interface. public List getTreeByUserName(String userName) { User user = userService.getUserByUserName(userName); // Get the

B.1 Part of the codes for accessing the directory tree resource management interface. public List getTreeByUserName(String userName) { User user = userService.getUserByUserName(userName); // Get the user's first-level tree node List reeNodes = treeNodeDAO.findChildrenByUserIDAndLevelNum(user.getUserID(), 1); // Traverse all trees from top to bottom based on the relationship among tree nodes and return the complete collection of tree nodes return getChildrenTreeByTreeNodes(treeNodes); } B.2 Part of the codes for the storage management subsystem. if (blocks == null) { this.blocks = new HashMap(); } else { blocks.clear(); } / / Find blocks which the same type field as the resources type List tmp = blockDao.find("type='" + rt.toString() + "'"); Iterator it = tmp.iterator(); //Select non full block while (it.hasNext()) { Block b = (Block) it.next(); blocks.put(b.getId(), b); if (BLOCK_STATUS_USE.equals(b.getStatus())) { currBlockId = b.getId();} } info("loading:" + blocks.toString()); B.3 The main code when the user logs in is as follows. public boolean loginByUserEmail(String email, String password,boolean rememberMe) { User tempUser; // Call DAO and return User instance tempUser = userDAO.findByEmail(email); // Determines whether the Users instance is empty) if(tempUser == null){ return false; } tempUser.getEmail(),rememberMe); UsernamePasswordToken token = new UsernamePasswordToken(tempUser.getUsername(), password); token.setRememberMe(rememberMe); Subject currentuser = SecurityUtils.getSubject(); //verify password try { currentuser.login(token); return true; } catch (AuthenticationException e) { e.printStackTrace(); ltempUser.getUsername()}; return false; } } B.4 Part of codes to change the password is as follows: public boolean changePassword(User user,String oldPassword, String newPassword, String newPassword2) { if(!newPassword.equals(newPassword2)){ throw new DataException("Two new passwords do not game "); return false; } PasswordService ps = new DefaultPasswordService(); if(!ps.passwordsGame(oldPassword, user.getPassword())){ throw new IncorrectCredentialsException("Incorrect password "); return false; } user.setPassword(ps.encryptPassword(newPassword)); userDAO.update(user); return true; } B.5 Part of the codes to obtain the main representative works of the user is following: User showuser = userService.getUserByUserName(userName); // representative works TreeNode MONode = treeNodeService.getSysTreeNodeByNodeNameAndUserID("representative works ",showuser.getUserID()); Album MOAlbum = albumService.getAlbumByTreeNodeID(MONode.getNodeID()); List slidePhotos = photoService.getPhotosByAlbumIDAndSortByViews(MOAlbum.getAlbumID(),3); if (slidePhotos.size() < 3) { List ComplementPhotos = photoService.getPhotosByUserIDAndSortByViews(showuser.getUserID(),3-slidePho tos.size()); slidePhoto.addAll(ComplementPhotos); } B.6 The core codes when commenting are as follows: public Comment postComment(int replyID, int sourceID, String sourceType, String content){ User user = getCurrentUser(); Comment comment = new Comment(user.getUserID(),sourceID,sourceType,replyID,content); comment.setCreateTime(DataTransfer.getCurrentTime()); commentDAO.insertComment(comment); return comment; } B.7 Part of the codes for moving photos is following: public boolean movePhoto(int photoID, int albumID) throws SourceNotFoundException, InternalServerException, PrivilegeDeniedException, SourceUpdateFailException { if (!isCurrentUserOwn(photoID) || !albumService.isCurrentUserOwn(albumID)) { throw new PrivilegeDeniedException("Insufficient privilege "); } Album toAlbum = albumService.getAlbumByAlbumID(albumID); Photo p = getPhotoByPhotoID(photoID); if (p.getAlbumID() == toAlbum.getAlbumID()) { return false; } Album srcAlbum = albumService.getAlbumByAlbumID(p.getAlbumID()); toAlbum.setPhotoNum(toAlbum.getPhotoNum() + 1); albumService.updateAlbum(toAlbum); srcAlbum.setPhotoNum(srcAlbum.getPhotoNum() - 1); albumService.updateAlbum(srcAlbum); p.setAlbumID(toAlbum.getAlbumID()); return true; } B.8 Part of the codes for modifying albums is following: Album album = albumService.getAlbumByAlbumID(albumID); if(name==""){ name=" (Unnamed) "; } // Write the changed information to the album entity album.setAlbumName(name); album.setDescription(description); album.setPhotoCategory(DataTransfer.photoCategroiesToString(photoCategory Service.getValidPhotoCtgs(photoCtgIDs))); TreeNode treenode = treeNodeService.getTreeNodeByAlbum(album.getAlbumID()); if(!treenode.getNodeName().equals(album.getAlbumName())){ //check privilege if(!treenode.isUserDefine()){ throw new PrivilegeDeniedException("Insufficient privilege: system album "); }else{ // Update the tree node name treenode.setNodeName(album.getAlbumName()); treeNodeService.updateTreeNode(treenode); } } // Update album information album.setUpdateTime(DataTransfer.getCurrentTime()); albumDAO.update(album); B.9 Part of the codes for deleting collections is following: public boolean removeCollection (int sourceID, String sourceType){ Collection collection = collectionService.getCollectionByUserIDAndSource(getCurrentUser().getUserID( ),sourceID,sourceType); if(collection==null){ returen false; } collectionDAO.deleteByID(collection.getCollectionID); collecttionService.updateCollectionNum(getCurrentUser().getUserID(),re sourceType,-1); return ture; } B.10 Part of the codes for creating competitions is following: public boolean newCompetition(String title, String starDate, String endDate , String resultDate ,Int manageID, Int reviewerID){ User user = getCurrentUser(); // Check user privilege if(!user.getStatus()==4){ throw new PrivilegeDeniedException("Insufficient privilege "); } Competition newCompetition= new Competition(); try { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); Date sdate = fmt.parse(starDate); Date edate = fmt.parse(endDate); Date rdate = fmt.parse(resultDate); } catch (ParseException e) { e.printStackTrace(); } new Competition.setTitle(title); newCompetition.setStartDate(sdate); newCompetition.setEndDate(edate); newCompetition.setResultDate(rdate); newCompetition.setAdministratorID(manageID); newCompetition.setReviewerID(reviewerID); Competition DAO.insert(newCompetition); return true; } B.11 Part of the codes for contributing is following: Photo p = new Photo(); CompetitionRelation cr=new GameRelation(); try { String photoCompetition = picFile.getOriginalFilename(); / / To prevent duplicate file with same names overwriting String filename = FileOperation.createUniqueName(photoName); String[] temp=storageManage.createResourceEntityAndURL(picFile); File dirs = new File(String[0]); // Check if the File instance exists, and if it does not exist, create a new file instance if (!dirs.exists()) { dirs.mkdirs(); } // Upload the photo and save the relevant information File photoFile = new File(tempUploaDir + filename); picFile.transferTo(photoFile); p.setPhotoName(photoName.substring(0, photoName.lastIndexOf("."))); p.setUploadTime(DataTransfer.getCurrentTime()); p.setUserID(userID); p.setGameID(gameID); photoDAO.insert(p); cr.setGameID(gameID); cr.setUserID(userID); r.setPhotoID(p.getIPhotoD()); cr.setCreateTime(DataTransfer.getCurrentTime()); gamerelationDAO.insert(cr); }catch (Exception e){ e.printStackTrace(); throw new RuntimeException("Photo uploading fails "); } B.12 Part of the codes for reviewing is following: public boolean changePrice(){ User user = getCurrentUser(); if(!user.getStatus()==2){ throw new PrivilegeDeniedException("You cant review"); } CompetitionRelation competitionrelation = competition RelationService.getCompetitionRelationByPhotoIDandGameID(photoID,gameID); competitionrelation.setPrize(prize); competitionRelationDAO.update(gamerelation); return true; } B.13 Part of the codes for arranging by upload time is following: List photos = new ArrayList(); List competitionRelations = new ArrayList< CompetitionRelation >(); Map sortmethods = new HashMap(); // to obtain specific sort parameters according to the incoming data switch (sortType) { case UPLOAD: { sortmethods.put("Property", "CREATE"); sortmethods.put("Direction", "DESC"); } break; case PRIZE: { sortmethods.put("Property ", "PRIZE"); sortmethods.put("Direction", "DESC"); } break; case VIEW:{ sortmethods.put("Property ", "VIEWNUM"); sortmethods.put("Direction", "DESC"); } break; case LIIKE:{ sortmethods.put("Property ", "LIKENUM"); sortmethods.put("Direction", "DESC"); } break; default: break; } / / the game relationship table is needed for sorting by winning situation, and other sorting methods only need photo table if(sortmethods.get("Property").equals("PRIZE")){ competitionRelations=competitionRelationServic.getcompetition RelationsByCompetitionID(competitionID, new PageBounds(page,15,Order.create(sortmethods.get("Property"),sortmethods.get( "Direction")))); photos=photoServic.getPhotosByCompetition Relations(competitionRelations); }else{ photos=photoServic.getPhotosByCompetitionID(competitionID, new PageBounds(page,15,Order.create(sortmethods.get("Property"),sortmethods.get( "Direction")))); } B. 14 Parts of the codes of giving a photo like is as follows: public void updateLikeNum(int resourceID, String resourceType) { / / Firstly determine the type of giving like targets, and then perform its related operations if(resourceType.equals(ResourceType.PHOTO.toString())){ Photo photo = photoService.getPhotoByPhotoID(resourceID); photo.setLikeNum(photo.getLIkeNum() +1); photoService.updatePhotoOnNum(photo); }else if(resourceType.equals(ResourceType.ALBUM.toString())){ Album album = albumService.getAlbumByAlbumID(resourceID); album.seLiketNum(album.getLikeNum() +1); albumService.updateAlbumOnNum(album); } else{ return; } return; }

CAN SOMEBODY WRITE THE MAIN FUNCTION FOR THIS CODE? AND ALSO SHOW ME HOW TO RUN THIS CODE ON ECLIPSE JAVA?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions