From dbfe0a18aec73d54e4941e3cd0f555fffa9bcbe1 Mon Sep 17 00:00:00 2001 From: Roshan Piyush Date: Thu, 11 Jan 2024 00:01:40 +0530 Subject: [PATCH 1/2] Upgrade django from 3.x to 4.1.x (#229) * Upgrade django from 3.x to 4.1.x ( * Increase community container memory --- deploy/docker/docker-compose.yml | 6 +++--- services/workshop/crapi/migrations/0001_initial.py | 4 ++-- services/workshop/crapi/user/tests.py | 4 ++-- services/workshop/crapi_site/settings.py | 2 +- services/workshop/requirements.txt | 11 ++++++----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/deploy/docker/docker-compose.yml b/deploy/docker/docker-compose.yml index b3eb9c45..e552f18c 100755 --- a/deploy/docker/docker-compose.yml +++ b/deploy/docker/docker-compose.yml @@ -100,7 +100,7 @@ services: resources: limits: cpus: '0.3' - memory: 128M + memory: 192M crapi-workshop: container_name: crapi-workshop @@ -194,8 +194,8 @@ services: deploy: resources: limits: - cpus: '0.3' - memory: 128M + cpus: '0.5' + memory: 256M mongodb: container_name: mongodb diff --git a/services/workshop/crapi/migrations/0001_initial.py b/services/workshop/crapi/migrations/0001_initial.py index 35fc5d65..b0cbd678 100644 --- a/services/workshop/crapi/migrations/0001_initial.py +++ b/services/workshop/crapi/migrations/0001_initial.py @@ -36,7 +36,7 @@ class Migration(migrations.Migration): ('jwt_token', models.CharField(max_length=500, null=True, unique=True)), ('number', models.CharField(max_length=255, null=True)), ('password', models.CharField(max_length=255)), - ('role', models.IntegerField(choices=[(2, 1), (0, 0)], default=0)), + ('role', models.IntegerField(choices=[(1, 'User'), (2, 'Mechanic'), (3, 'Admin')], default=1)), ], options={ 'db_table': 'user_login', @@ -165,7 +165,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Coupon', fields=[ - ('coupon_code', models.CharField(primary_key=True, max_length=255)), + ('coupon_code', models.CharField(max_length=255, primary_key=True, serialize=False)), ('amount', models.CharField(max_length=255)), ], options={ diff --git a/services/workshop/crapi/user/tests.py b/services/workshop/crapi/user/tests.py index 483f12f5..657f4fbd 100644 --- a/services/workshop/crapi/user/tests.py +++ b/services/workshop/crapi/user/tests.py @@ -26,7 +26,7 @@ from django.test import TestCase, Client from django.utils import timezone from utils import messages -from crapi.user.views import DEFAULT_LIMIT +from crapi_site import settings from crapi.user.models import User, UserDetails logger = logging.getLogger('UserTest') @@ -105,7 +105,7 @@ def test_get_api_management_users_all(self): response = self.client.get('/workshop/api/management/users/all', **self.auth_headers) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content) - self.assertEqual(len(response_data['users']), DEFAULT_LIMIT) + self.assertEqual(len(response_data['users']), settings.DEFAULT_LIMIT) response = self.client.get('/workshop/api/management/users/all?limit=10&offset=0', **self.auth_headers) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content) diff --git a/services/workshop/crapi_site/settings.py b/services/workshop/crapi_site/settings.py index c9dfd170..85026849 100644 --- a/services/workshop/crapi_site/settings.py +++ b/services/workshop/crapi_site/settings.py @@ -176,7 +176,7 @@ def get_env_value(env_variable): 'NAME': 'test_crapi', 'USER': get_env_value('DB_USER'), }, - 'CONN_MAX_AGE': 60, + 'CONN_MAX_AGE': 0, }, 'mongodb': { 'ENGINE': 'djongo', diff --git a/services/workshop/requirements.txt b/services/workshop/requirements.txt index 99e60605..6662beb2 100644 --- a/services/workshop/requirements.txt +++ b/services/workshop/requirements.txt @@ -1,18 +1,19 @@ -bcrypt==3.1.7 -Django~=3.2.19 +bcrypt==4.1.2 +Django~=4.1.13 cryptography==40.0.2 django-cors-headers==4.0.0 django-db-cascade-2==0.3.5 django-environ==0.10.0 django-extended-choices==1.3.3 -django-extensions==3.2.1 +django-extensions==3.2.3 django-health-check==3.17.0 djangorestframework==3.14.0 django-sslserver==0.22 -djongo==1.3.6 +djongo==1.3.6 #max version for django 4.1.13 +sqlparse==0.2.4 #djongo-dependency psycopg2==2.9.9 PyJWT==2.7.0 -pymongo==3.12.3 +pymongo==3.13.0 pyOpenSSL==23.1.1 requests==2.30.0 Werkzeug==2.0.3 From f34fb50f6fb3088436024c13277c10ddb134822f Mon Sep 17 00:00:00 2001 From: Roshan Piyush Date: Sun, 4 Feb 2024 21:27:36 +0530 Subject: [PATCH 2/2] Better seeding of users (#231) * Better seeding of default data --- README.md | 6 + deploy/vagrant/crapi.service | 2 +- openapi-spec/openapi-spec.json | 8 +- .../com/crapi/config/InitialDataConfig.java | 122 +++++++++++++++--- .../java/com/crapi/constant/TestUsers.java | 58 ++++++++- .../java/com/crapi/entity/VehicleDetails.java | 13 +- .../java/com/crapi/entity/VehicleModel.java | 2 +- .../main/java/com/crapi/model/SeedUser.java | 37 +++++- .../repository/VehicleCompanyRepository.java | 24 ++++ .../service/Impl/ProfileServiceImpl.java | 1 + .../java/com/crapi/utils/GenerateVIN.java | 27 ++-- .../com/crapi/utils/VehicleModelData.java | 58 --------- 12 files changed, 259 insertions(+), 99 deletions(-) create mode 100644 services/identity/src/main/java/com/crapi/repository/VehicleCompanyRepository.java delete mode 100644 services/identity/src/main/java/com/crapi/utils/VehicleModelData.java diff --git a/README.md b/README.md index f7ad1eea..9a8c29a9 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,12 @@ You can use prebuilt images generated by our CI workflow. docker-compose -f docker-compose.yml --compatibility up -d ``` + - To Stop and Cleanup crAPI + + ``` + docker-compose -f docker-compose.yml --compatibility down –volumes + ``` + Visit [http://localhost:8888](http://localhost:8888) **Note**: All emails are sent to mailhog service by default and can be checked on diff --git a/deploy/vagrant/crapi.service b/deploy/vagrant/crapi.service index 54e5c01d..ab6285cf 100644 --- a/deploy/vagrant/crapi.service +++ b/deploy/vagrant/crapi.service @@ -8,7 +8,7 @@ Type=oneshot RemainAfterExit=true WorkingDirectory=/opt/crapi ExecStart=/bin/bash -c "/usr/local/bin/docker-compose up -d --remove-orphans" -ExecStop=/bin/bash -c "/usr/local/bin/docker-compose down" +ExecStop=/bin/bash -c "/usr/local/bin/docker-compose down –volumes" [Install] WantedBy=multi-user.target diff --git a/openapi-spec/openapi-spec.json b/openapi-spec/openapi-spec.json index 4c28d3b9..5d86dc81 100644 --- a/openapi-spec/openapi-spec.json +++ b/openapi-spec/openapi-spec.json @@ -1125,7 +1125,7 @@ "schema" : { "type" : "string", "format" : "uuid", - "example" : "0be319f0-f0dd-44aa-af0b-af927f3a383f" + "example" : "1929186d-8b67-4163-a208-de52a41f7301" } } ] }, @@ -2730,8 +2730,8 @@ } }, "example" : { - "id" : 23, - "vin" : "0FOPP90TFEE927859", + "id" : 3, + "vin" : "1G1OP124017231334", "owner" : { "email" : "victim.one@example.com", "number" : "4156895423" @@ -3096,7 +3096,7 @@ "example" : { "nickname" : "Hacker", "email" : "hacker@darkweb.com", - "vehicleid" : "abac4018-5a38-466c-ab7f-361908afeab6", + "vehicleid" : "4bae9968-ec7f-4de3-a3a0-ba1b2ab5e5e5", "profile_pic_url" : "", "created_at" : "2021-09-16T01:46:32.432Z" } diff --git a/services/identity/src/main/java/com/crapi/config/InitialDataConfig.java b/services/identity/src/main/java/com/crapi/config/InitialDataConfig.java index b2a4e2c7..31c6441b 100644 --- a/services/identity/src/main/java/com/crapi/config/InitialDataConfig.java +++ b/services/identity/src/main/java/com/crapi/config/InitialDataConfig.java @@ -15,17 +15,23 @@ package com.crapi.config; import com.crapi.constant.TestUsers; +import com.crapi.entity.ProfileVideo; import com.crapi.entity.User; import com.crapi.entity.UserDetails; +import com.crapi.entity.VehicleCompany; import com.crapi.entity.VehicleDetails; +import com.crapi.entity.VehicleLocation; +import com.crapi.entity.VehicleModel; +import com.crapi.enums.EFuelType; import com.crapi.enums.ERole; import com.crapi.model.SeedUser; import com.crapi.repository.*; import com.crapi.service.VehicleService; +import com.crapi.utils.GenerateVIN; import com.crapi.utils.UserData; -import com.crapi.utils.VehicleLocationData; -import com.crapi.utils.VehicleModelData; import java.util.ArrayList; +import java.util.List; +import java.util.Random; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -40,8 +46,16 @@ public class InitialDataConfig { private static final Logger logger = LoggerFactory.getLogger(InitialDataConfig.class); + private static long seed = 0; + + private Random random; + + GenerateVIN generateVIN; + @Autowired VehicleLocationRepository vehicleLocationRepository; + @Autowired VehicleCompanyRepository vehicleCompanyRepository; + @Autowired VehicleModelRepository vehicleModelRepository; @Autowired VehicleDetailsRepository vehicleDetailsRepository; @@ -56,30 +70,57 @@ public class InitialDataConfig { @Autowired PasswordEncoder encoder; - public void addLocation() { - if (CollectionUtils.isEmpty(vehicleLocationRepository.findAll())) { - VehicleLocationData vehicleLocationData = new VehicleLocationData(); - vehicleLocationRepository.saveAll(vehicleLocationData.getVehicleLocationData()); - } + public void createModels() { + VehicleCompany vehicleCompany = new VehicleCompany("Hyundai"); + VehicleModel vehicleModel = + new VehicleModel("Creta", EFuelType.DIESEL, vehicleCompany, "images/hyundai-creta.jpg"); + vehicleModelRepository.save(vehicleModel); + + vehicleCompany = new VehicleCompany("Lamborghini"); + vehicleModel = + new VehicleModel( + "Aventador", EFuelType.PETROL, vehicleCompany, "images/lamborghini-aventador.jpg"); + vehicleModel = vehicleModelRepository.save(vehicleModel); + + vehicleCompany = new VehicleCompany("Mercedes-Benz"); + vehicleModel = + new VehicleModel( + "GLA Class", EFuelType.DIESEL, vehicleCompany, "images/mercedesbenz-gla.jpg"); + vehicleModelRepository.save(vehicleModel); + + vehicleCompany = new VehicleCompany("BMW"); + vehicleModel = + new VehicleModel("5 Series", EFuelType.PETROL, vehicleCompany, "images/bmw-5.jpg"); + vehicleModelRepository.save(vehicleModel); + + vehicleCompany = new VehicleCompany("Audi"); + vehicleModel = new VehicleModel("RS7", EFuelType.DIESEL, vehicleCompany, "images/audi-rs7.jpg"); + vehicleModelRepository.save(vehicleModel); + + vehicleCompany = new VehicleCompany("MG Motor"); + vehicleModel = + new VehicleModel( + "Hector Plus", EFuelType.PETROL, vehicleCompany, "images/mgmotor-hectorplus.jpg"); + vehicleModel = vehicleModelRepository.save(vehicleModel); } public void addVehicleModel() { if (CollectionUtils.isEmpty(vehicleModelRepository.findAll())) { - VehicleModelData vehicleModelData = new VehicleModelData(); - vehicleModelRepository.saveAll(vehicleModelData.getModelList()); + createModels(); } } @EventListener public void setup(ApplicationReadyEvent event) { - - addLocation(); + random = new Random(); + random.setSeed(seed); + generateVIN = new GenerateVIN(); addVehicleModel(); addUser(); } public void addUser() { - if (CollectionUtils.isEmpty(userDetailsRepository.findAll())) { + if (CollectionUtils.isEmpty(userDetailsRepository.findAll()) || false) { ArrayList userDetailList = new TestUsers().getUsers(); for (SeedUser userDetails : userDetailList) { boolean user = @@ -88,7 +129,12 @@ public void addUser() { userDetails.getEmail(), userDetails.getPassword(), userDetails.getNumber(), - userDetails.getRole()); + userDetails.getRole(), + userDetails.getCarid(), + userDetails.getVin(), + userDetails.getPincode(), + userDetails.getLatitude(), + userDetails.getLongitude()); if (!user) { logger.error("Fail to create predefined users"); } @@ -96,24 +142,62 @@ public void addUser() { } } + public VehicleDetails createVehicle( + String carId, String vin, String pincode, String latitude, String longitude) { + List modelList = null; + modelList = vehicleModelRepository.findAll(); + if (modelList != null) { + VehicleLocation vehicleLocation = new VehicleLocation(latitude, longitude); + VehicleDetails vehicleDetails = new VehicleDetails(carId, pincode, vin); + VehicleModel vehicleModel = modelList.get(random.nextInt(modelList.size())); + vehicleModel = vehicleModelRepository.findById(vehicleModel.getId()).get(); + vehicleDetails.setVehicleLocation(vehicleLocation); + vehicleDetails = vehicleDetailsRepository.save(vehicleDetails); + vehicleDetails.setModel(vehicleModel); + vehicleDetails = vehicleDetailsRepository.save(vehicleDetails); + logger.debug("Created vehicle for {} successfully", vehicleDetails); + return vehicleDetails; + } + return null; + } + public boolean predefineUserData( - String name, String email, String password, String number, ERole role) { + String name, + String email, + String password, + String number, + ERole role, + String carId, + String vin, + String pincode, + String latitude, + String longitude) { UserData userData = new UserData(); VehicleDetails vehicleDetails = null; UserDetails userDetails = null; try { User user = new User(email, number, encoder.encode(password), role); user = userRepository.save(user); + user = userRepository.findById(user.getId()).get(); userDetails = userData.getPredefineUser(name, user); - userDetailsRepository.save(userDetails); - vehicleDetails = vehicleService.createVehicle(); + userDetails = userDetailsRepository.save(userDetails); + vehicleDetails = createVehicle(carId, vin, pincode, latitude, longitude); if (vehicleDetails != null) { vehicleDetails.setOwner(user); vehicleDetailsRepository.save(vehicleDetails); - return true; + } else { + logger.error("Fail to create vehicle for user {}", email); + return false; } - logger.error("Fail to create vehicle for user {}", email); - return false; + // generate random bytes + byte[] videoBytes = new byte[10]; + random.nextBytes(videoBytes); + String videoName = userDetails.getName().replace(" ", "_") + "_video"; + String conversionParam = "-v codec h264"; + ProfileVideo profileVideo = new ProfileVideo(videoName, videoBytes, user); + profileVideo.setConversion_params(conversionParam); + profileVideoRepository.save(profileVideo); + return true; } catch (Exception e) { logger.error("Fail to create user {}, Exception :: {}", email, e); return false; diff --git a/services/identity/src/main/java/com/crapi/constant/TestUsers.java b/services/identity/src/main/java/com/crapi/constant/TestUsers.java index 165184aa..c4236222 100644 --- a/services/identity/src/main/java/com/crapi/constant/TestUsers.java +++ b/services/identity/src/main/java/com/crapi/constant/TestUsers.java @@ -25,15 +25,63 @@ public class TestUsers { public TestUsers() { users.add( new SeedUser( - "Adam", "adam007@example.com", "9876895423", "adam007!123", ERole.ROLE_PREDEFINE)); + "Adam", + "adam007@example.com", + "9876895423", + "adam007!123", + ERole.ROLE_PREDEFINE, + "f89b5f21-7829-45cb-a650-299a61090378", + "7ECOX34KJTV359804", + "123456", + "32.778889", + "-91.919243")); users.add( new SeedUser( - "Pogba", "pogba006@example.com", "9876570006", "pogba006!123", ERole.ROLE_PREDEFINE)); + "Pogba", + "pogba006@example.com", + "9876570006", + "pogba006!123", + ERole.ROLE_PREDEFINE, + "cd515c12-0fc1-48ae-8b61-9230b70a845b", + "8VAUI03PRUQ686911", + "123456", + "31.284788", + "-92.471176")); users.add( new SeedUser( - "Robot", "robot001@example.com", "9876570001", "robot001!123", ERole.ROLE_PREDEFINE)); - users.add(new SeedUser("Test", "test@example.com", "9876540001", "Test!123", ERole.ROLE_USER)); + "Robot", + "robot001@example.com", + "9876570001", + "robot001!123", + ERole.ROLE_PREDEFINE, + "4bae9968-ec7f-4de3-a3a0-ba1b2ab5e5e5", + "0NKPZ09IHOP508673", + "123456", + "37.746880", + "-84.301460")); users.add( - new SeedUser("Admin", "admin@example.com", "9010203040", "Admin!123", ERole.ROLE_ADMIN)); + new SeedUser( + "Test", + "test@example.com", + "9876540001", + "Test!123", + ERole.ROLE_USER, + "1929186d-8b67-4163-a208-de52a41f7301", + "8IGEF39BZUJ159285", + "123456", + "38.206348", + "-84.270172")); + users.add( + new SeedUser( + "Admin", + "admin@example.com", + "9010203040", + "Admin!123", + ERole.ROLE_ADMIN, + "f5c506f5-3af2-4120-926c-64ad8b10ddc2", + "6NBBY70FWUM324316", + "123456", + "37.406769", + "-94.705528")); } } diff --git a/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java b/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java index 53eb684f..4665b4e7 100644 --- a/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java +++ b/services/identity/src/main/java/com/crapi/entity/VehicleDetails.java @@ -33,7 +33,7 @@ public class VehicleDetails { private long id; @Column(name = "uuid", updatable = false, nullable = false, unique = true) - private UUID uuid = UUID.randomUUID(); + private UUID uuid; private String pincode; private String vin; @@ -41,7 +41,7 @@ public class VehicleDetails { private EStatus status; @Transient List previousOwners; - @OneToOne(cascade = CascadeType.ALL) + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "vehicle_model_id") private VehicleModel model; @@ -54,7 +54,16 @@ public class VehicleDetails { private User owner; public VehicleDetails(String pincode, String vin) { + this.uuid = UUID.randomUUID(); + this.pincode = pincode; + this.vin = vin; + this.status = EStatus.ACTIVE; + this.year = LocalDate.now().getYear(); + this.previousOwners = Arrays.asList(); + } + public VehicleDetails(String uuid, String pincode, String vin) { + this.uuid = UUID.fromString(uuid); this.pincode = pincode; this.vin = vin; this.status = EStatus.ACTIVE; diff --git a/services/identity/src/main/java/com/crapi/entity/VehicleModel.java b/services/identity/src/main/java/com/crapi/entity/VehicleModel.java index d9b68dae..b2ca69dd 100644 --- a/services/identity/src/main/java/com/crapi/entity/VehicleModel.java +++ b/services/identity/src/main/java/com/crapi/entity/VehicleModel.java @@ -32,7 +32,7 @@ public class VehicleModel implements Serializable { private EFuelType fuel_type; private String vehicle_img; - @OneToOne(cascade = CascadeType.ALL) + @ManyToOne(cascade = CascadeType.ALL) private VehicleCompany vehiclecompany; public VehicleModel() {} diff --git a/services/identity/src/main/java/com/crapi/model/SeedUser.java b/services/identity/src/main/java/com/crapi/model/SeedUser.java index fe92b721..06362058 100644 --- a/services/identity/src/main/java/com/crapi/model/SeedUser.java +++ b/services/identity/src/main/java/com/crapi/model/SeedUser.java @@ -43,11 +43,46 @@ public class SeedUser { @Size(min = 3, max = 100) private ERole role; - public SeedUser(String name, String email, String number, String password, ERole role) { + @NotBlank + @Size(min = 3, max = 100) + private String carid; + + @NotBlank + @Size(min = 3, max = 100) + private String vin; + + @NotBlank + @Size(min = 3, max = 100) + private String pincode; + + @NotBlank + @Size(min = 3, max = 100) + private String latitude; + + @NotBlank + @Size(min = 3, max = 100) + private String longitude; + + public SeedUser( + String name, + String email, + String number, + String password, + ERole role, + String carid, + String vin, + String pincode, + String latitude, + String longitude) { this.name = name; this.email = email; this.number = number; this.password = password; this.role = role; + this.carid = carid; + this.vin = vin; + this.pincode = pincode; + this.latitude = latitude; + this.longitude = longitude; } } diff --git a/services/identity/src/main/java/com/crapi/repository/VehicleCompanyRepository.java b/services/identity/src/main/java/com/crapi/repository/VehicleCompanyRepository.java new file mode 100644 index 00000000..7b1aefff --- /dev/null +++ b/services/identity/src/main/java/com/crapi/repository/VehicleCompanyRepository.java @@ -0,0 +1,24 @@ +/* + * Licensed under the Apache License, Version 2.0 (the “License”); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an “AS IS” BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.crapi.repository; + +import com.crapi.entity.VehicleCompany; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface VehicleCompanyRepository extends JpaRepository { + VehicleCompany findByName(String name); +} diff --git a/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java b/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java index 62963301..c203711c 100644 --- a/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java +++ b/services/identity/src/main/java/com/crapi/service/Impl/ProfileServiceImpl.java @@ -104,6 +104,7 @@ public ProfileVideo uploadProfileVideo(MultipartFile file, HttpServletRequest re profileVideo.setVideo_name(file.getOriginalFilename()); } else { profileVideo = new ProfileVideo(file.getOriginalFilename(), file.getBytes(), user); + profileVideo.setConversion_params(conversionParam); } profileVideoRepository.save(profileVideo); return profileVideo; diff --git a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java index 7af345c0..b3c5a5b8 100644 --- a/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java +++ b/services/identity/src/main/java/com/crapi/utils/GenerateVIN.java @@ -14,12 +14,23 @@ package com.crapi.utils; +import java.util.Random; + public class GenerateVIN { static String charsequence = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static String num = "0123456789"; String vin = ""; String pincode = ""; + Random random; + + public GenerateVIN() { + random = new Random(); + } + + public GenerateVIN(long seed) { + random = new Random(seed); + } /** @return random generate pin code for add vehicle */ public String generatePincode() { @@ -34,26 +45,26 @@ public String generateVIN() { } public String getChar(int num) { - String random = ""; - for (int j = 0; j <= num; j++) random += randomCharacter(); - return random; + String randStr = ""; + for (int j = 0; j <= num; j++) randStr += randomCharacter(); + return randStr; } public String getNum(int num) { - String random = ""; - for (int k = 0; k <= num; k++) random += randomNumber(); - return random; + String randNum = ""; + for (int k = 0; k <= num; k++) randNum += randomNumber(); + return randNum; } public String randomCharacter() { int n = charsequence.length(); - int r = (int) (n * Math.random()); + int r = random.nextInt(n); return charsequence.substring(r, r + 1); } public String randomNumber() { int n = num.length(); - int r = (int) (n * Math.random()); + int r = random.nextInt(n); return num.substring(r, r + 1); } } diff --git a/services/identity/src/main/java/com/crapi/utils/VehicleModelData.java b/services/identity/src/main/java/com/crapi/utils/VehicleModelData.java deleted file mode 100644 index a7a9cf04..00000000 --- a/services/identity/src/main/java/com/crapi/utils/VehicleModelData.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the “License”); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an “AS IS” BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.crapi.utils; - -import com.crapi.entity.VehicleCompany; -import com.crapi.entity.VehicleModel; -import com.crapi.enums.EFuelType; -import java.util.ArrayList; -import java.util.List; - -public class VehicleModelData { - - /** @return List of hard coded Vehicle Model and Company for pre data setup. */ - public List getModelList() { - List vehicleModelList = new ArrayList<>(); - vehicleModelList.add( - new VehicleModel( - "Creta", EFuelType.DIESEL, new VehicleCompany("Hyundai"), "images/hyundai-creta.jpg")); - vehicleModelList.add( - new VehicleModel( - "Aventador", - EFuelType.PETROL, - new VehicleCompany("Lamborghini"), - "images/lamborghini-aventador.jpg")); - vehicleModelList.add( - new VehicleModel( - "GLA Class", - EFuelType.DIESEL, - new VehicleCompany("Mercedes-Benz"), - "images/mercedesbenz-gla.jpg")); - vehicleModelList.add( - new VehicleModel( - "5 Series", EFuelType.PETROL, new VehicleCompany("BMW"), "images/bmw-5.jpg")); - vehicleModelList.add( - new VehicleModel( - "RS7", EFuelType.DIESEL, new VehicleCompany("Audi"), "images/audi-rs7.jpg")); - vehicleModelList.add( - new VehicleModel( - "Hector Plus", - EFuelType.PETROL, - new VehicleCompany("MG Motor"), - "images/mgmotor-hectorplus.jpg")); - - return vehicleModelList; - } -}