This commit is contained in:
ltiongku
2024-08-12 23:55:08 +08:00
parent ef1fb9f6e0
commit 53f9acd922
6 changed files with 124 additions and 108 deletions

View File

@@ -1,11 +1,10 @@
package com.safeqr.app.qrcode.service;
import static com.safeqr.app.constants.CommonConstants.*;
import com.safeqr.app.qrcode.dto.request.QRCodePayload;
import com.safeqr.app.qrcode.dto.URLVerificationResponse;
import com.safeqr.app.qrcode.entity.URLEntity;
import com.safeqr.app.qrcode.model.URLModel;
import com.safeqr.app.qrcode.repository.URLRepository;
import com.safeqr.app.spark.service.MLModelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,9 +28,11 @@ public class URLVerificationService {
private static final int READ_TIMEOUT_MS = 10000;
private static final Logger logger = LoggerFactory.getLogger(URLVerificationService.class);
private final URLRepository urlRepository;
private final MLModelService mlModelService;
@Autowired
public URLVerificationService(URLRepository urlRepository) {
public URLVerificationService(URLRepository urlRepository, MLModelService mlModelService) {
this.urlRepository = urlRepository;
this.mlModelService = mlModelService;
}
// Regular expression pattern for shortening services
@@ -425,22 +426,8 @@ public class URLVerificationService {
return INFO_NON_SECURE_CONNECTION;
}
public URLVerificationResponse verifyURL(QRCodePayload payload) {
URLVerificationResponse response = new URLVerificationResponse();
try {
java.net.URL url = new java.net.URL(payload.getData());
String protocol = url.getProtocol();
if ("https".equalsIgnoreCase(protocol)) {
response.setSecure(true);
response.setMessage("The connection is secure.");
} else {
response.setSecure(false);
response.setMessage("The connection is not secure.");
}
} catch (Exception e) {
response.setSecure(false);
response.setMessage("Invalid URL.");
}
return response;
// Get Classification using ML Model
public String getClassification(URLModel urlModel){
return mlModelService.predict(urlModel);
}
}