Skip to content

Commit

Permalink
Create log and insert log in other class and change Cover To ProfileP…
Browse files Browse the repository at this point in the history
…ictures and create class r,n For Log and Request and class ToJson
  • Loading branch information
bardiademon committed Feb 14, 2020
1 parent 7294410 commit 869b88a
Show file tree
Hide file tree
Showing 60 changed files with 2,269 additions and 157 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ build/
### Me ###
.gitignore
files/
.src/main/java/com/bardiademon/CyrusMessenger/Controller/Rest/Test.java
Binary file removed files/Default/Images/ic_not_login.png
Binary file not shown.
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,34 @@
<version>1.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.corundumstudio.socketio/netty-socketio -->
<dependency>
<groupId>com.corundumstudio.socketio</groupId>
<artifactId>netty-socketio</artifactId>
<version>1.7.7</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-websocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
</dependency>

</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bardiademon/CyrusMessenger/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static Code CreateCodeLong ()

public static String Name ()
{
Code code = new Code (50 , true , true , true , false);
Code code = new Code (150 , true , true , true , false);
code.createCode ();
return code.getCode ();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.bardiademon.CyrusMessenger.Controller;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -12,30 +16,39 @@ public class AnswerToClient
private int statusCode;
private Map<String, Object> message;
private boolean ok;

@JsonIgnore
private HttpServletResponse response;

@JsonIgnore
private HttpServletRequest request;

public AnswerToClient (int StatusCode , boolean Ok)
{
this.statusCode = StatusCode;
this.ok = Ok;
message = new LinkedHashMap<> ();
}

@JsonIgnore
public static AnswerToClient OK ()
{
return new AnswerToClient (200 , true);
}

@JsonIgnore
public static AnswerToClient error400 ()
{
return new AnswerToClient (400 , false);
}

@JsonIgnore
public static AnswerToClient OneAnswer (AnswerToClient _AnswerToClient , Object Answer)
{
return OneAnswer (_AnswerToClient , CUK.answer.name () , Answer);
}

@JsonIgnore
public static AnswerToClient OneAnswer (AnswerToClient _AnswerToClient , String Key , Object Answer)
{
_AnswerToClient.put (Key , Answer);
Expand All @@ -45,6 +58,7 @@ public static AnswerToClient OneAnswer (AnswerToClient _AnswerToClient , String
/**
* KeyAnswer => Key => KeyAnswer[0] , Answer => KeyAnswer[1] | Key => KeyAnswer[2] , Answer => KeyAnswer[3] ,....
*/
@JsonIgnore
public static AnswerToClient KeyAnswer (AnswerToClient _AnswerToClient , Object... KeyAnswer)
{
for (int i = 0, len = ((KeyAnswer.length) - 1); i < len; i += 2)
Expand All @@ -53,50 +67,87 @@ public static AnswerToClient KeyAnswer (AnswerToClient _AnswerToClient , Object.
return _AnswerToClient;
}

@JsonIgnore
public static AnswerToClient RequestIsNull ()
{
AnswerToClient answerToClient = error400 ();
answerToClient.put (CUK.answer.name () , "request_is_null");
return answerToClient;
}

@JsonIgnore
public static AnswerToClient AccountDeactive ()
{
AnswerToClient answerToClient = New (HttpServletResponse.SC_FORBIDDEN);
answerToClient.put (CUK.answer.name () , "account_deactive");
return answerToClient;
}

@JsonIgnore
public static AnswerToClient ServerError ()
{
AnswerToClient answerToClient = new AnswerToClient (500 , false);
answerToClient.put (CUK.answer.name () , "please_try_again");
return answerToClient;
}

@JsonIgnore
public static AnswerToClient NotLoggedIn ()
{
AnswerToClient answerToClient = new AnswerToClient (400 , false);
AnswerToClient answerToClient = AnswerToClient.error400 ();
answerToClient.put (CUK.answer.name () , "not_logged_in");
return answerToClient;
}

@JsonIgnore
public static AnswerToClient New (int StatusCode , boolean Ok)
{
return new AnswerToClient (StatusCode , Ok);
}

@JsonIgnore
public static AnswerToClient New (int StatusCode)
{
return New (StatusCode , false);
}

@JsonIgnore
public void setResponse (HttpServletResponse response)
{
this.response = response;
setStatusCode ();
}

public void setMessage (Map<String, Object> message)
{
this.message = message;
}

@JsonIgnore
public HttpServletRequest getRequest ()
{
return request;
}

@JsonIgnore
public HttpServletResponse getResponse ()
{
return response;
}

@JsonIgnore
public void setRequest (HttpServletRequest request)
{
this.request = request;
}

@JsonIgnore
public void setReqRes (HttpServletRequest request , HttpServletResponse response)
{
if (getRequest () == null) setRequest (request);
if (getResponse () == null) setResponse (response);
}

private void setStatusCode ()
{
response.setStatus (getStatusCode ());
Expand All @@ -113,6 +164,7 @@ public int getStatusCode ()
return statusCode;
}

@JsonProperty ("message")
public Map<String, Object> getMessage ()
{
return message;
Expand All @@ -123,9 +175,37 @@ public boolean isOk ()
return ok;
}


// CUK => Commonly used keys
public enum CUK
{
answer
}

@JsonIgnore
@Override
public String toString ()
{
try
{
ObjectMapper objectMapper = new ObjectMapper ();
return objectMapper.writeValueAsString (this);
}
catch (JsonProcessingException e)
{
e.printStackTrace ();
return null;
}
}

public void setStatusCode (int statusCode)
{
this.statusCode = statusCode;
}

public void setOk (boolean ok)
{
this.ok = ok;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public class GetCover
}

@RequestMapping (value = {"/{username}" , "/" , ""}, produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.GET)
public @ResponseBody
byte[] get (
public @ResponseBody byte[] get (
@PathVariable (value = "username",
required = false) String username ,
HttpServletResponse response ,
Expand All @@ -87,7 +86,7 @@ byte[] get (
if (username == null || username.equals ("")) return error (Path.IMAGE_NOT_FOUND);

CheckLogin checkLogin = new CheckLogin (codeLogin , userLoginService.Repository);
if (!checkLogin.isValid ()) return error (Path.IC_NOT_LOGIN);
if (!checkLogin.isValid ()) return error (Path.IC_NOT_LOGGED);

MainAccount mainAccount = findUsername (username);
if (mainAccount != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.bardiademon.CyrusMessenger.bardiademon.Default.Path;
import com.bardiademon.CyrusMessenger.bardiademon.GetSize;
import com.bardiademon.CyrusMessenger.bardiademon.IO.CheckImage;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -54,7 +53,7 @@ public UploadCover (UserLoginService _UserLoginService , MainAccountService _Mai
{

CheckImage checkImage = new CheckImage ();
if (checkImage.check (cover , FilenameUtils.getExtension (cover.getOriginalFilename ())))
if (checkImage.valid (cover))
{
if (cover.getSize () > DSize.SIZE_COVER)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.bardiademon.CyrusMessenger.Model.Database.Users.Users.MainAccount.UserFriends.UserFriends;
import com.bardiademon.CyrusMessenger.Model.Database.Users.Users.MainAccount.UserFriends.UserFriendsService;
import com.bardiademon.CyrusMessenger.Model.Database.Users.Users.UserLogin.UserLoginService;
import com.bardiademon.CyrusMessenger.Model.FindInTheDatabase.FITD_Username;
import com.bardiademon.CyrusMessenger.Model.WorkingWithADatabase.FITD_Username;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ private AnswerToClient newInfoUser (HttpServletResponse res , @RequestBody Reque
if (requestGeneral.isUpdatedFamily () || !requestGeneral.isNull (requestGeneral.getFamily ()))
answerToClient.put (KeyAnswer.family.name () , requestGeneral.isUpdatedFamily ());

if (requestGeneral.isUpdatedUsername () || !requestGeneral.isNull (requestGeneral.getUsername ()))
answerToClient.put (KeyAnswer.username.name () , requestGeneral.isUpdatedUsername ());

if (requestGeneral.isUpdatedMylink () || !requestGeneral.isNull (requestGeneral.getMylink ()))
answerToClient.put (KeyAnswer.mylink.name () , requestGeneral.isUpdatedMylink ());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public final class RequestGeneral
private String bio;
private String name;
private String family;
private String username;
private String mylink;


Expand All @@ -18,16 +17,6 @@ public final class RequestGeneral
public RequestGeneral ()
{
}

public RequestGeneral (String bio , String name , String family , String username , String mylink)
{
this.bio = bio;
this.name = name;
this.family = family;
this.username = username;
this.mylink = mylink;
}

public String getBio ()
{
return bio;
Expand Down Expand Up @@ -58,16 +47,6 @@ public void setFamily (String family)
this.family = family;
}

public String getUsername ()
{
return username;
}

public void setUsername (String username)
{
this.username = username;
}

public String getMylink ()
{
return mylink;
Expand All @@ -80,7 +59,7 @@ public void setMylink (String mylink)

public boolean thereIsAtLeastOneTrue ()
{
return (isNull (getBio ()) || isNull (getName ()) || isNull (getFamily ()) || isNull (getUsername ()) || isNull (getMylink ()));
return (isNull (getBio ()) || isNull (getName ()) || isNull (getFamily ()) || isNull (getMylink ()));
}

public boolean isNull (String str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public GetInfoProfile (UserLoginService _UserLoginService , MainAccountService _
answerToClient = AnswerToClient.RequestIsNull ();
else
{
answerToClient = showProfile.showProfile (res , codeLogin , request.getIdUser ());
answerToClient = showProfile.showProfile (res , codeLogin , request.getIdUser () , request.getUsername ());

if (answerToClient.isOk () && answerToClient.getMessage ().containsKey (ShowProfile.KeyAnswer.i_can.name ()) && ((boolean) answerToClient.getMessage ().get (ShowProfile.KeyAnswer.i_can.name ())))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public final class RequestGetInfoProfile extends RequestGeneral
@JsonProperty ("id_user")
private long idUser;

private String username;

public RequestGetInfoProfile ()
{
super ();
Expand All @@ -23,5 +25,13 @@ public void setIdUser (long idUser)
this.idUser = idUser;
}

public String getUsername ()
{
return username;
}

public void setUsername (String username)
{
this.username = username;
}
}
Loading

0 comments on commit 869b88a

Please sign in to comment.