Skip to content

Commit 4bc3788

Browse files
committed
fix naming; add PictureBase64 container class.
1 parent ecb475e commit 4bc3788

31 files changed

+310
-219
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.louay.projects.model;
2+
3+
import com.louay.projects.model.chains.communications.AccountPicture;
4+
import com.louay.projects.model.chains.users.Client;
5+
import com.louay.projects.model.constants.UserGender;
6+
import com.louay.projects.model.constants.UserType;
7+
import com.louay.projects.model.dao.CreateUsersDAO;
8+
import com.louay.projects.model.dao.SelectUsersDAO;
9+
import com.louay.projects.model.util.date.NowDate;
10+
import com.louay.projects.model.util.file.FileProcess;
11+
import com.louay.projects.model.util.pool.MyConnectionPool;
12+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
13+
14+
import javax.imageio.ImageIO;
15+
import java.awt.*;
16+
import java.awt.image.BufferedImage;
17+
import java.io.*;
18+
import java.sql.SQLException;
19+
import java.util.Base64;
20+
import java.util.Iterator;
21+
import java.util.Set;
22+
23+
public class Main {
24+
public static void main(String[] args) {
25+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
26+
context.scan("com.louay.projects.model");
27+
context.refresh();
28+
29+
Client user = context.getBean(Client.class);
30+
user.setUsername("louay");
31+
user.setPassword("123");
32+
user.setAccountPermission(UserType.CLIENT.getType());
33+
user.setDateCreate(NowDate.getNowTimestamp());
34+
35+
user.setFirstName("louay");
36+
user.setLastName("amr");
37+
user.setBirthday(java.sql.Date.valueOf("1994-10-08"));
38+
user.setAge(user.getAgeFromBirthday());
39+
user.setGender(UserGender.MALE.getGender());
40+
user.setTelephone("00962");
41+
user.setEmail("louay@projects");
42+
user.setCountry("jordan");
43+
user.setState("az");
44+
user.setAddress("qatar street");
45+
46+
CreateUsersDAO createUsersDAO = (CreateUsersDAO) context.getBean("usersDAO");
47+
48+
49+
FileProcess fileProcess = context.getBean(FileProcess.class);
50+
51+
byte [] bytes = null;
52+
try {
53+
bytes = fileProcess.readAPicture("C:\\Users\\Oday Amr\\Pictures\\Annotation 2020-03-08 210620.png");
54+
} catch (IOException e) {
55+
e.printStackTrace();
56+
}
57+
58+
for (int i = 0; i < bytes.length; i++) {
59+
System.out.print(bytes[i]);
60+
}
61+
System.out.println();
62+
63+
AccountPicture picture = context.getBean(AccountPicture.class);
64+
picture.setUsername(user.getUsername());
65+
MyConnectionPool pool = (MyConnectionPool) context.getBean("pool");
66+
java.sql.Blob blob = pool.initBlob();
67+
picture.setPicture(blob);
68+
69+
try {
70+
int size = (int) picture.getPicture().length();
71+
for (int i = 0; i <size ; i++) {
72+
System.out.print(picture.getPicture().getBytes(1, size)[i]);
73+
}
74+
} catch (SQLException e) {
75+
e.printStackTrace();
76+
}
77+
picture.setUploadDate(NowDate.getNowTimestamp());
78+
picture.setPictureName("Annotation 2020-03-08 210620.png");
79+
80+
File file = new File(String.valueOf(picture.getPicture()));
81+
file.renameTo(new File("Annotation 2020-03-08 210620.png"));
82+
83+
84+
SelectUsersDAO insertUserPostDAO = (SelectUsersDAO) context.getBean("usersDAO");
85+
Set<AccountPicture> set = (Set<AccountPicture>) insertUserPostDAO.findPictureByUsername(picture);
86+
try (OutputStream out = new BufferedOutputStream(new FileOutputStream("C:\\Users\\Oday Amr\\Desktop\\" + set.iterator().next().getPictureName()))) {
87+
out.write(set.iterator().next().getPicture().getBytes(1,(int)set.iterator().next().getPicture().length()));
88+
String f = Base64.getEncoder().encodeToString(set.iterator().next().getPicture().getBytes(1,(int)set.iterator().next().getPicture().length()));
89+
System.out.println();
90+
System.out.println(f);
91+
92+
93+
} catch (FileNotFoundException e) {
94+
e.printStackTrace();
95+
} catch (IOException e) {
96+
e.printStackTrace();
97+
} catch (SQLException e) {
98+
e.printStackTrace();
99+
}
100+
101+
}
102+
}

src/main/java/com/louay/projects/model/chains/communications/AccountComments.java

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.louay.projects.model.chains.communications;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.context.annotation.Scope;
5+
import org.springframework.stereotype.Component;
6+
7+
import java.sql.Timestamp;
8+
import java.util.Objects;
9+
10+
@Configuration
11+
@Component
12+
@Scope("prototype")
13+
public class AccountTextPost {
14+
private Long idPost;
15+
private String idUsername;
16+
private StringBuilder post;
17+
private java.sql.Timestamp postDate;
18+
19+
public AccountTextPost() {
20+
}
21+
22+
public Long getIdPost() {
23+
return idPost;
24+
}
25+
26+
public void setIdPost(Long idPost) {
27+
this.idPost = idPost;
28+
}
29+
30+
public String getIdUsername() {
31+
return idUsername;
32+
}
33+
34+
public void setIdUsername(String idUsername) {
35+
this.idUsername = idUsername;
36+
}
37+
38+
public StringBuilder getPost() {
39+
return post;
40+
}
41+
42+
public void setPost(String post) {
43+
this.post = new StringBuilder(post);
44+
}
45+
46+
public Timestamp getPostDate() {
47+
return postDate;
48+
}
49+
50+
public void setPostDate(Timestamp postDate) {
51+
this.postDate = postDate;
52+
}
53+
54+
@Override
55+
public boolean equals(Object o) {
56+
if (this == o) return true;
57+
if (!(o instanceof AccountTextPost)) return false;
58+
AccountTextPost that = (AccountTextPost) o;
59+
return getIdPost().compareTo(that.getIdPost()) == 0;
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return Objects.hash(getIdPost());
65+
}
66+
67+
@Override
68+
public String toString() {
69+
return "AccountTextPost{" +
70+
"idPost=" + idPost +
71+
", idUsername='" + idUsername + '\'' +
72+
", post=" + post +
73+
", postDate=" + postDate +
74+
'}';
75+
}
76+
}

src/main/java/com/louay/projects/model/chains/communications/group/GroupComments.java renamed to src/main/java/com/louay/projects/model/chains/communications/group/GroupTextPost.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
@Configuration
1111
@Component
1212
@Scope("prototype")
13-
public class GroupComments {
14-
private Long idComment;
13+
public class GroupTextPost {
14+
private Long idPost;
1515
private String idGroup;
1616
private String username;
17-
private StringBuilder comment;
18-
private java.sql.Timestamp commentsDate;
17+
private StringBuilder post;
18+
private java.sql.Timestamp postDate;
1919

20-
public GroupComments() {
20+
public GroupTextPost() {
2121
}
2222

23-
public Long getIdComment() {
24-
return idComment;
23+
public Long getIdPost() {
24+
return idPost;
2525
}
2626

27-
public void setIdComment(Long idComment) {
28-
this.idComment = idComment;
27+
public void setIdPost(Long idPost) {
28+
this.idPost = idPost;
2929
}
3030

3131
public String getIdGroup() {
@@ -44,43 +44,43 @@ public void setUsername(String username) {
4444
this.username = username;
4545
}
4646

47-
public StringBuilder getComment() {
48-
return comment;
47+
public StringBuilder getPost() {
48+
return post;
4949
}
5050

51-
public void setComment(String comment) {
52-
this.comment = new StringBuilder(comment);
51+
public void setPost(String post) {
52+
this.post = new StringBuilder(post);
5353
}
5454

55-
public Timestamp getCommentsDate() {
56-
return commentsDate;
55+
public Timestamp getPostDate() {
56+
return postDate;
5757
}
5858

59-
public void setCommentsDate(Timestamp commentsDate) {
60-
this.commentsDate = commentsDate;
59+
public void setPostDate(Timestamp postDate) {
60+
this.postDate = postDate;
6161
}
6262

6363
@Override
6464
public boolean equals(Object o) {
6565
if (this == o) return true;
66-
if (!(o instanceof GroupComments)) return false;
67-
GroupComments that = (GroupComments) o;
68-
return getIdComment().compareTo(that.getIdComment()) == 0;
66+
if (!(o instanceof GroupTextPost)) return false;
67+
GroupTextPost that = (GroupTextPost) o;
68+
return getIdPost().equals(that.getIdPost());
6969
}
7070

7171
@Override
7272
public int hashCode() {
73-
return Objects.hash(getIdComment());
73+
return Objects.hash(getIdPost());
7474
}
7575

7676
@Override
7777
public String toString() {
78-
return "GroupComments{" +
79-
"idComment=" + idComment +
78+
return "GroupTextPost{" +
79+
"idPost=" + idPost +
8080
", idGroup='" + idGroup + '\'' +
8181
", username='" + username + '\'' +
82-
", comment=" + comment +
83-
", commentsDate=" + commentsDate +
82+
", post=" + post +
83+
", postDate=" + postDate +
8484
'}';
8585
}
8686
}

src/main/java/com/louay/projects/model/chains/util/PictureDirection.java renamed to src/main/java/com/louay/projects/model/chains/util/PictureBase64.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
@Configuration
88
@Component
99
@Scope("prototype")
10-
public class PictureDirection {
10+
public class PictureBase64 {
1111
String username;
12-
String fileName;
13-
String path;
12+
String pictureBase64;
13+
1414

1515
public String getUsername() {
1616
return username;
@@ -20,28 +20,19 @@ public void setUsername(String username) {
2020
this.username = username;
2121
}
2222

23-
public String getFileName() {
24-
return fileName;
25-
}
26-
27-
public void setFileName(String fileName) {
28-
this.fileName = fileName;
29-
}
30-
31-
public String getPath() {
32-
return path;
23+
public String getPictureBase64() {
24+
return pictureBase64;
3325
}
3426

35-
public void setPath(String path) {
36-
this.path = path;
27+
public void setPictureBase64(String pictureBase64) {
28+
this.pictureBase64 = pictureBase64;
3729
}
3830

3931
@Override
4032
public String toString() {
41-
return "PictureDirection{" +
33+
return "PictureBase64{" +
4234
"username='" + username + '\'' +
43-
", fileName='" + fileName + '\'' +
44-
", path='" + path + '\'' +
35+
", pictureBase64='" + pictureBase64 + '\'' +
4536
'}';
4637
}
4738
}

0 commit comments

Comments
 (0)