Skip to content

Commit 03abe07

Browse files
working on #157
1 parent e213a4f commit 03abe07

File tree

5 files changed

+82
-29
lines changed

5 files changed

+82
-29
lines changed

src/main/java/org/woehlke/twitterwall/oodm/entities/Url.java

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,63 @@ public class Url extends AbstractDomainObject<Url> implements DomainObjectEntity
6262

6363
@Transient
6464
public boolean isUrlAndExpandedTheSame(){
65+
if(url == null){
66+
return false;
67+
}
68+
if(expanded == null){
69+
return false;
70+
}
71+
if(this.url.isEmpty()){
72+
return false;
73+
}
74+
if(this.expanded.isEmpty()){
75+
return false;
76+
}
6577
return url.compareTo(expanded) == 0;
6678
}
6779

80+
@Transient
81+
public boolean isRawUrlsFromDescription() {
82+
if(this.display == null){
83+
return false;
84+
}
85+
if(this.expanded == null){
86+
return false;
87+
}
88+
if(this.display.isEmpty()){
89+
return false;
90+
}
91+
if(this.expanded.isEmpty()){
92+
return false;
93+
}
94+
return (this.display.compareTo(UNDEFINED)==0)&&(this.expanded.compareTo(UNDEFINED)==0);
95+
}
96+
97+
@Transient
98+
@Override
99+
public boolean isValid() {
100+
if(this.url == null){
101+
return false;
102+
}
103+
if(this.expanded == null){
104+
return false;
105+
}
106+
if(this.display == null){
107+
return false;
108+
}
109+
if(this.url.isEmpty()){
110+
return false;
111+
}
112+
if(this.expanded.isEmpty()){
113+
return false;
114+
}
115+
if(this.display.isEmpty()){
116+
return false;
117+
}
118+
boolean isInvalid = this.isRawUrlsFromDescription()||this.isUrlAndExpandedTheSame();
119+
return !isInvalid;
120+
}
121+
68122
public Url(Task createdBy, Task updatedBy,String display, String expanded, String url) {
69123
super(createdBy,updatedBy);
70124
this.display = display;
@@ -134,16 +188,6 @@ public String toString() {
134188
"}\n";
135189
}
136190

137-
@Override
138-
public boolean isValid() {
139-
boolean isInvalid = (this.url == null)||(this.url.isEmpty()||isRawUrlsFromDescription())||(this.url.compareTo(this.expanded)==0);
140-
return !isInvalid;
141-
}
142-
143-
public boolean isRawUrlsFromDescription() {
144-
return (this.getDisplay().compareTo(UNDEFINED)==0)&&(this.getExpanded().compareTo(UNDEFINED)==0);
145-
}
146-
147191
@Override
148192
public boolean equals(Object o) {
149193
if (this == o) return true;

src/main/java/org/woehlke/twitterwall/oodm/entities/parts/Entities.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public String toString() {
384384

385385
public String getFormattedText(String formattedText ) {
386386

387-
formattedText = getFormattedTextForUserProfiles(formattedText);
387+
//formattedText = getFormattedTextForUserProfiles(formattedText);
388388

389389
Set<HashTag> tags = this.getHashTags();
390390
formattedText = getFormattedTextForHashTags(tags,formattedText);
@@ -395,7 +395,7 @@ public String getFormattedText(String formattedText ) {
395395
Set<Url> urls = this.getUrls();
396396
formattedText = getFormattedTextForUrls(urls, formattedText);
397397

398-
formattedText = getFormattedTextForUrls( formattedText );
398+
//formattedText = getFormattedTextForUrls( formattedText );
399399

400400
Set<Mention> mentions = this.getMentions();
401401
formattedText = super.getFormattedTextForMentions(mentions, formattedText);

src/main/java/org/woehlke/twitterwall/oodm/repositories/custom/impl/UserRepositoryImpl.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
@Repository
2020
public class UserRepositoryImpl implements UserRepositoryCustom {
2121

22-
private final EntityManager entityManager;
23-
24-
private JdbcTemplate jdbcTemplate;
25-
26-
@Autowired
27-
public UserRepositoryImpl(EntityManager entityManager,DataSource dataSource) {
28-
this.entityManager = entityManager;
29-
this.jdbcTemplate = new JdbcTemplate(dataSource);
30-
}
3122

3223
@Override
3324
public User findByUniqueId(User domainObject) {
@@ -43,11 +34,6 @@ public User findByUniqueId(User domainObject) {
4334
}
4435
}
4536

46-
@Override
47-
public Page<User> findNotYetFollower(Pageable pageRequest) {
48-
return null;
49-
}
50-
5137
@Override
5238
public Page<Object2Entity> findAllUser2HashTag(Pageable pageRequest) {
5339
String pagerSQL = " OFFSET "+pageRequest.getOffset()+" LIMIT "+pageRequest.getPageSize();
@@ -107,4 +93,14 @@ public Page<Object2Entity> findAllUser2TickerSymbol(Pageable pageRequest) {
10793
PageImpl<Object2Entity> resultPage = new PageImpl<>(list,pageRequest,total);
10894
return resultPage;
10995
}
96+
97+
private final EntityManager entityManager;
98+
99+
private JdbcTemplate jdbcTemplate;
100+
101+
@Autowired
102+
public UserRepositoryImpl(EntityManager entityManager,DataSource dataSource) {
103+
this.entityManager = entityManager;
104+
this.jdbcTemplate = new JdbcTemplate(dataSource);
105+
}
110106
}

src/main/java/org/woehlke/twitterwall/oodm/service/impl/UrlServiceImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ public UrlServiceImpl(UrlRepository urlRepository, TaskRepository taskRepository
3232
public Url findByUrl(String url) {
3333
String name = "findByUrl "+url+" ";
3434
if(url == null){
35-
throw new IllegalArgumentException("Url.findByUrl: url == null");
35+
log.debug(name+"Url.findByUrl: url == null");
36+
return null;
37+
//throw new IllegalArgumentException("Url.findByUrl: url == null");
3638
}
3739
Url result = urlRepository.findByUrl(url);
38-
log.debug(name+result.toString());
40+
if(result == null){
41+
log.debug(name+"Url.findByUrl: url == null");
42+
} else {
43+
log.debug(name+result.toString());
44+
}
3945
return result;
4046
}
4147

src/main/java/org/woehlke/twitterwall/scheduled/service/persist/impl/StoreEntitiesProcessImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ public Entities storeEntitiesProcess(Entities entities, Task task) {
3434
for (Url myUrl : entities.getUrls()) {
3535
if(myUrl != null) {
3636
if (myUrl.isValid()) {
37-
Url urlPers = urlService.store(myUrl, task);
37+
Url urlPers = urlService.findByUrl(myUrl.getUrl());
38+
if(urlPers != null){
39+
urlPers.setDisplay(myUrl.getDisplay());
40+
urlPers.setExpanded(myUrl.getExpanded());
41+
urlPers = urlService.store(urlPers, task);
42+
} else {
43+
urlPers = urlService.store(myUrl, task);
44+
}
3845
urls.add(urlPers);
3946
} else if (myUrl.isRawUrlsFromDescription()){
4047
String urlStr = myUrl.getUrl();

0 commit comments

Comments
 (0)