Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalber committed Jun 17, 2017
1 parent 80acd19 commit 59996a6
Show file tree
Hide file tree
Showing 28 changed files with 1,018 additions and 149 deletions.
5 changes: 5 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
</pydev_project>
96 changes: 94 additions & 2 deletions src/main/java/com/weberfly/controller/AcountController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.weberfly.controller;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

Expand All @@ -25,7 +28,7 @@

import com.weberfly.entities.User;
import com.weberfly.service.SessionService;

import com.weberfly.service.TweetAnalyseService;
import com.weberfly.service.UserService;
import com.weberfly.service.threads.PostLocationDetection;
import com.weberfly.util.CustomErrorType;
Expand All @@ -40,6 +43,8 @@ public class AcountController {
UserService userService;
@Autowired
SessionService sessionService;
@Autowired
TweetAnalyseService tweetAnalyseService;

@Autowired
private ApplicationContext applicationContext;
Expand Down Expand Up @@ -73,9 +78,33 @@ public Principal user(Principal principal) {
return principal;
}

@RequestMapping(value = "/compareTols", method = RequestMethod.GET)
public ResponseEntity<?> getCompareRate() {
Map<String, Map<String, Double>> stats = new HashMap<>();
try {
Map<String, Double> ntltkAnalyseRAte = tweetAnalyseService.getAnalyseRateForNLTK();
stats.put("nltk", ntltkAnalyseRAte);

Map<String, Double> dumaxkAnalyseRAte = tweetAnalyseService.getAnalyseRateForDumax();
stats.put("dumax", dumaxkAnalyseRAte);
Map<String, Double> gatekAnalyseRAte = tweetAnalyseService.getAnalyseRateForGate();
stats.put("gate", gatekAnalyseRAte);
Map<String, Double> combainingkAnalyseRAte = tweetAnalyseService.getAnalyseRateGeneral();
stats.put("combaining", combainingkAnalyseRAte);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



return new ResponseEntity<Map<String, Map<String, Double>>>(stats, HttpStatus.CREATED);
}


@RequestMapping(value = "/session", method = RequestMethod.GET)
public ResponseEntity<?> getConnected() {

User user=(User)session.getAttribute("connected");
if (user == null) {
logger.error("user not found ");
Expand Down Expand Up @@ -112,6 +141,69 @@ public ResponseEntity<?> singleFileUpload(@RequestParam("file") MultipartFile fi
e.printStackTrace();
}

return new ResponseEntity(HttpStatus.CREATED);
}

@RequestMapping(value = "/uploadFilePositive", method = RequestMethod.POST)
public ResponseEntity<?> uploadFile1(@RequestParam("file") MultipartFile file){

if (file.isEmpty()) {
return new ResponseEntity(new CustomErrorType(" error file is empty"), HttpStatus.CONFLICT);
}

try {

// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
Files.write(path, bytes);
session.setAttribute("positiveData", path.toUri().toURL());
} catch (IOException e) {
e.printStackTrace();
}

return new ResponseEntity(HttpStatus.CREATED);
}
@RequestMapping(value = "/uploadFileNegative", method = RequestMethod.POST)
public ResponseEntity<?> uploadFile2(@RequestParam("file") MultipartFile file){

if (file.isEmpty()) {
return new ResponseEntity(new CustomErrorType(" error file is empty"), HttpStatus.CONFLICT);
}

try {

// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
session.setAttribute("negativeData", path.toUri().toURL());
Files.write(path, bytes);

} catch (IOException e) {
e.printStackTrace();
}

return new ResponseEntity(HttpStatus.CREATED);
}
@RequestMapping(value = "/uploadFileNeutral", method = RequestMethod.POST)
public ResponseEntity<?> uploadFile3(@RequestParam("file") MultipartFile file){

if (file.isEmpty()) {
return new ResponseEntity(new CustomErrorType(" error file is empty"), HttpStatus.CONFLICT);
}

try {

// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
session.setAttribute("neutralData", path.toUri().toURL());
Files.write(path, bytes);

} catch (IOException e) {
e.printStackTrace();
}

return new ResponseEntity(HttpStatus.CREATED);
}
}
8 changes: 5 additions & 3 deletions src/main/java/com/weberfly/controller/CategoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -74,10 +75,11 @@ public ResponseEntity<?> create(@RequestBody Category item, UriComponentsBuilder
logger.info("Creating item : {}", item);
logger.info("{}",categoryService.isExist(item));
if (categoryService.isExist(item)) {
logger.error("Unable to create. A item with name {} already exist", item.getName());
logger.error("Unable to create. A item with name {} already exist", item.getTitle());
return new ResponseEntity(new CustomErrorType("Unable to create. A item with name " +
item.getName()+ " already exist."),HttpStatus.CONFLICT);
item.getTitle()+ " already exist."),HttpStatus.CONFLICT);
}
item.setDateCreation(new Date());
categoryService.save(item);

HttpHeaders headers = new HttpHeaders();
Expand All @@ -99,7 +101,7 @@ public ResponseEntity<?> update(@PathVariable("id") long id, @RequestBody Catego
HttpStatus.NOT_FOUND);
}

currentitem.setName(item.getName());
currentitem.setTitle(item.getTitle());


categoryService.save(currentitem);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/weberfly/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ResponseEntity<?> getItem(@PathVariable("id")long id) {

// -------------------Retrieve Single item by User------------------------------------------

@RequestMapping(value = "/posts/byUser", method = RequestMethod.GET)
@RequestMapping(value = "/posts/findByUser", method = RequestMethod.GET)
public ResponseEntity<?> getItems() {
User u=(User)session.getAttribute("connected");
List<Post> items = postservice.findByUser(u);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/weberfly/controller/TwitterController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.weberfly.controller;

import java.sql.Date;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -72,11 +73,12 @@ public ResponseEntity<?> planScheduledTask(@RequestBody TwitterKeyWord item,UriC
logger.error("key word list is empty ");
return new ResponseEntity(new CustomErrorType("item not found "), HttpStatus.NOT_FOUND);
}
System.out.println(item);


TwitterTimerThread task=new TwitterTimerThread(item,tweetService);
applicationContext.getAutowireCapableBeanFactory().autowireBean(item);
task.createTAsk();
item.setStat(TwitterKeyWord.threadStat.running);
return new ResponseEntity<>(HttpStatus.OK);
}

Expand Down Expand Up @@ -129,6 +131,8 @@ public ResponseEntity<?> create(@RequestBody TwitterKeyWord item, UriComponentsB
return new ResponseEntity(new CustomErrorType("Unable to create. A item with name " +
item.getWord()+ " already exist."),HttpStatus.CONFLICT);
}
item.setDateCreation(new java.util.Date());
item.setStat(TwitterKeyWord.threadStat.stoped);
twitterKeyWordService.save(item);

HttpHeaders headers = new HttpHeaders();
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/weberfly/dao/CategoryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
@Repository
public interface CategoryRepository extends JpaRepository<Category, Long>{

public Category findByType(String type);

public Category findByName(String Name);
public Category findByTitle(String title);
}
48 changes: 24 additions & 24 deletions src/main/java/com/weberfly/entities/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
Expand All @@ -29,24 +30,27 @@
@Entity
@Table(name="Category")
public class Category implements Serializable{

/**
* Description of the property id.
*/
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id ;
private String name ;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;


@ManyToOne(cascade = CascadeType.ALL)
private TypeCategory type ;

@OneToMany(cascade = CascadeType.ALL,mappedBy="category")
private List<CategoryItem> categoryItems = new ArrayList<CategoryItem>();

@ManyToMany(mappedBy="categories")
private List<User> users = new ArrayList<User>();
private Date dateCreation;

public Date getDateCreation() {
return dateCreation;
}

public void setDateCreation(Date dateCreation) {
this.dateCreation = dateCreation;
}

@OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
private List<TwitterKeyWord> keyWords;

public Long getId() {
return id;
Expand All @@ -56,23 +60,19 @@ public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
public String getTitle() {
return title;
}

public void setName(String name) {
this.name = name;
public void setTitle(String title) {
this.title = title;
}

public TypeCategory getType() {
return type;
}

public void setType(TypeCategory type) {
this.type = type;
public void setKeyWords(List<TwitterKeyWord> keyWords) {
this.keyWords = keyWords;
}





}
23 changes: 23 additions & 0 deletions src/main/java/com/weberfly/entities/TwitterKeyWord.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

Expand All @@ -35,6 +37,8 @@ public static enum Period{
private Long id;

private String word;

private Date dateCreation;

@Enumerated(EnumType.STRING)
private threadStat stat;
Expand All @@ -50,6 +54,9 @@ public static enum Period{
@OneToMany(cascade = CascadeType.ALL, mappedBy = "keyWord")
private List<Twitte> twittes;

@ManyToOne(cascade = CascadeType.MERGE ,fetch= FetchType.EAGER)
private Category category;


public Long getId() {
return id;
Expand Down Expand Up @@ -103,6 +110,22 @@ public String getThreadPlaningDescription() {
public void setThreadPlaningDescription(String threadPlaningDescription) {
this.threadPlaningDescription = threadPlaningDescription;
}

public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}

public Date getDateCreation() {
return dateCreation;
}

public void setDateCreation(Date dateCreation) {
this.dateCreation = dateCreation;
}

@Override
public String toString() {
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/weberfly/entities/TypeCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ public class TypeCategory implements Serializable{
private String name ;


/**
* Description of the property categorys.
*/
@OneToMany( mappedBy="type",cascade=CascadeType.ALL)
private List<Category> categorys ;


public Long getId() {
return Id;
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/weberfly/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ public static enum Role{
@JoinTable(name = "User_Folowers", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "folowing_id", referencedColumnName = "id"))
private List<User> following;

@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "User_Categories", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "category_id", referencedColumnName = "id"))
private List<Category> categories;
// @ManyToMany(cascade = CascadeType.ALL)
// @JoinTable(name = "User_Categories", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "category_id", referencedColumnName = "id"))
// private List<Category> categories;

@ManyToMany(mappedBy="following")
private List<User> users;

Expand Down Expand Up @@ -209,11 +210,6 @@ public void setFollowing(List<User> following) {
this.following = following;
}



public void setCategories(List<Category> categories) {
this.categories = categories;
}


public void setTwitterKeyWords(List<TwitterKeyWord> twitterKeyWords) {
Expand Down
Loading

0 comments on commit 59996a6

Please sign in to comment.