Skip to content

Commit

Permalink
perf($Starter): abstract project property
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Johnny Miller (锺俊) committed Dec 29, 2020
1 parent 062ede6 commit b6996c8
Show file tree
Hide file tree
Showing 32 changed files with 245 additions and 364 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jmsoftware.maf.apigateway.security;
package com.jmsoftware.maf.apigateway.security.configuration;

import com.jmsoftware.maf.apigateway.security.impl.*;
import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafConfiguration;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
* <h1>ProjectProperty</h1>
Expand All @@ -13,7 +14,9 @@
* @date 2019-04-18 13:01
**/
@Data
@Validated
@Component
@SuppressWarnings("jol")
@ConfigurationProperties(prefix = "project.property")
public class ProjectProperty {
private String basePackage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jmsoftware.maf.authcenter;

import com.jmsoftware.maf.authcenter.universal.configuration.ProjectProperty;
import com.jmsoftware.maf.springbootstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.springbootstarter.helper.IpHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand All @@ -27,11 +27,11 @@
@SpringBootApplication
public class AuthCenterApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static ProjectProperty projectProperty;
private static MafProjectProperty mafProjectProperty;
private static IpHelper ipHelper;

public AuthCenterApplication(ProjectProperty projectProperty, IpHelper ipHelper) {
AuthCenterApplication.projectProperty = projectProperty;
public AuthCenterApplication(MafProjectProperty projectProperty, IpHelper ipHelper) {
AuthCenterApplication.mafProjectProperty = projectProperty;
AuthCenterApplication.ipHelper = ipHelper;
}

Expand All @@ -41,12 +41,12 @@ public static void main(String[] args) {
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
log.info("🖥 {}@{} started!", projectProperty.getProjectArtifactId(), projectProperty.getVersion());
log.info("⚙️ Environment: {}", projectProperty.getEnvironment());
log.info("🖥 {}@{} started!", mafProjectProperty.getProjectArtifactId(), mafProjectProperty.getVersion());
log.info("⚙️ Environment: {}", mafProjectProperty.getEnvironment());
log.info("⏳ Deployment duration: {} seconds ({} ms)", duration.getSeconds(), duration.toMillis());
log.info("⏰ App started at {} (timezone - {})", endInstant, TimeZone.getDefault().getDisplayName());
log.info("{} App running at{} - Local: http://localhost:{}{}/{} - Network: http://{}:{}{}/",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), projectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), projectProperty.getContextPath());
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import com.jmsoftware.maf.authcenter.permission.mapper.PermissionMapper;
import com.jmsoftware.maf.authcenter.permission.service.PermissionService;
import com.jmsoftware.maf.authcenter.role.service.RoleService;
import com.jmsoftware.maf.authcenter.universal.configuration.ProjectProperty;
import com.jmsoftware.maf.common.bean.ResponseBodyBean;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse;
import com.jmsoftware.maf.common.domain.authcenter.permission.PermissionType;
import com.jmsoftware.maf.common.domain.springbootstarter.HttpApiResourcesResponse;
import com.jmsoftware.maf.common.exception.BusinessException;
import com.jmsoftware.maf.springbootstarter.configuration.MafProjectProperty;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -44,7 +44,7 @@
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionPersistence> implements PermissionService {
private final RoleService roleService;
private final DiscoveryClient discoveryClient;
private final ProjectProperty projectProperty;
private final MafProjectProperty mafProjectProperty;
private final RestTemplate restTemplate;

@Override
Expand Down Expand Up @@ -84,8 +84,8 @@ public GetServicesInfoResponse getServicesInfo() throws BusinessException {
log.info("Getting service info from Service ID list: {}", serviceIdList);
val response = new GetServicesInfoResponse();
val mapper = new ObjectMapper();
val ignoredServiceIdList = Lists.newArrayList(projectProperty.getProjectArtifactId(),
"api-gateway", "spring-boot-admin");
val ignoredServiceIdList = Lists.newArrayList(mafProjectProperty.getProjectArtifactId(),
"api-gateway", "spring-boot-admin");
log.info("Ignored service ID list: {}", ignoredServiceIdList);
for (String serviceId : serviceIdList) {
if (ignoredServiceIdList.contains(serviceId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jmsoftware.maf.authcenter.universal.configuration;

import com.jmsoftware.maf.springbootstarter.configuration.MafProjectProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand All @@ -26,11 +27,11 @@ public class JwtConfiguration {
*/
private String jwtRedisKeyPrefix;

public JwtConfiguration(ProjectProperty projectProperty) {
this.signingKey = String.format("%s %s", projectProperty.getProjectParentArtifactId(), projectProperty.getVersion());
public JwtConfiguration(MafProjectProperty mafProjectProperty) {
this.signingKey = String.format("%s %s", mafProjectProperty.getProjectParentArtifactId(), mafProjectProperty.getVersion());
log.info("Initiated JWT signing key: {}. The specified key byte array is {} bits", this.signingKey,
this.signingKey.getBytes(StandardCharsets.UTF_8).length * 8);
jwtRedisKeyPrefix = String.format("%s:jwt:", projectProperty.getProjectParentArtifactId());
jwtRedisKeyPrefix = String.format("%s:jwt:", mafProjectProperty.getProjectParentArtifactId());
log.warn("Initiated 'jwtRedisKeyPrefix': {}", jwtRedisKeyPrefix);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jmsoftware.maf.authcenter.universal.configuration;

import com.jmsoftware.maf.springbootstarter.configuration.MafProjectProperty;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.context.annotation.Bean;
Expand All @@ -26,31 +27,31 @@
@EnableSwagger2
@RequiredArgsConstructor
public class Swagger2Configuration {
private final ProjectProperty projectProperty;
private final MafProjectProperty mafProjectProperty;

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage(projectProperty.getBasePackage()))
.apis(RequestHandlerSelectors.basePackage(mafProjectProperty.getBasePackage()))
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
val projectArtifactId = projectProperty.getProjectArtifactId();
val version = projectProperty.getVersion();
val developerEmail = projectProperty.getDeveloperEmail();
val developerUrl = projectProperty.getDeveloperUrl();
val projectArtifactId = mafProjectProperty.getProjectArtifactId();
val version = mafProjectProperty.getVersion();
val developerEmail = mafProjectProperty.getDeveloperEmail();
val developerUrl = mafProjectProperty.getDeveloperUrl();
return new ApiInfoBuilder()
.title(String.format("API for %s@%s", projectArtifactId, version))
.description(String.format("%s Artifact ID: %s Environment: %s",
projectProperty.getDescription(),
mafProjectProperty.getDescription(),
projectArtifactId,
projectProperty.getEnvironment()))
mafProjectProperty.getEnvironment()))
.contact(new Contact(String.format("%s, email: %s Home page: %s",
projectProperty.getDeveloperName(),
mafProjectProperty.getDeveloperName(),
developerEmail,
developerUrl),
developerUrl, developerEmail))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jmsoftware.maf.authcenter.universal.service.impl;

import com.jmsoftware.maf.authcenter.universal.configuration.ProjectProperty;
import com.jmsoftware.maf.authcenter.universal.service.CommonService;
import com.jmsoftware.maf.common.domain.ValidationTestPayload;
import com.jmsoftware.maf.springbootstarter.configuration.MafProjectProperty;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -27,12 +27,12 @@
@Service
@RequiredArgsConstructor
public class CommonServiceImpl implements CommonService {
private final ProjectProperty projectProperty;
private final MafProjectProperty mafProjectProperty;

@Override
public Map<String, Object> getApplicationInfo() {
var map = new HashMap<String, Object>(16);
var fieldsInfo = getFieldsInfo(projectProperty);
var fieldsInfo = getFieldsInfo(mafProjectProperty);
fieldsInfo.forEach(fieldInfo -> {
var type = fieldInfo.get("type");
if ("class java.lang.String".equals(type)) {
Expand Down
20 changes: 9 additions & 11 deletions auth-center/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ logging:
level:
com.jmsoftware: DEBUG

project:
property:
maf:
project-property:
base-package: @project.groupId@
context-path:
group-id: @project.groupId@
Expand All @@ -99,15 +99,6 @@ project:
developer-name: @developerName@
developer-email: @developerEmail@
developer-url: @developerUrl@

# Customize JWT configuration for development environment.
jwt:
configuration:
# an hour
ttl: 3600000
ttl-for-remember-me: 604800000

maf:
configuration:
ignored-url:
pattern:
Expand All @@ -120,3 +111,10 @@ maf:
- "/webjars/**"
- "/doc.html"
included-package-for-http-api-scan: ${project.property.base-package}

# Customize JWT configuration for development environment.
jwt:
configuration:
# an hour
ttl: 3600000
ttl-for-remember-me: 604800000
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jmsoftware.maf.exercisemis;

import com.jmsoftware.maf.exercisemis.universal.configuration.ProjectProperty;
import com.jmsoftware.maf.springbootstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.springbootstarter.helper.IpHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand All @@ -27,11 +27,11 @@
@SpringBootApplication
public class ExerciseMisApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static ProjectProperty projectProperty;
private static MafProjectProperty mafProjectProperty;
private static IpHelper ipHelper;

public ExerciseMisApplication(ProjectProperty projectProperty, IpHelper ipHelper) {
ExerciseMisApplication.projectProperty = projectProperty;
public ExerciseMisApplication(MafProjectProperty mafProjectProperty, IpHelper ipHelper) {
ExerciseMisApplication.mafProjectProperty = mafProjectProperty;
ExerciseMisApplication.ipHelper = ipHelper;
}

Expand All @@ -41,12 +41,12 @@ public static void main(String[] args) {
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
log.info("🖥 {}@{} started!", projectProperty.getProjectArtifactId(), projectProperty.getVersion());
log.info("⚙️ Environment: {}", projectProperty.getEnvironment());
log.info("🖥 {}@{} started!", mafProjectProperty.getProjectArtifactId(), mafProjectProperty.getVersion());
log.info("⚙️ Environment: {}", mafProjectProperty.getEnvironment());
log.info("⏳ Deployment duration: {} seconds ({} ms)", duration.getSeconds(), duration.toMillis());
log.info("⏰ App started at {} (timezone - {})", endInstant, TimeZone.getDefault().getDisplayName());
log.info("{} App running at{} - Local: http://localhost:{}{}/{} - Network: http://{}:{}/{}",
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), projectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), projectProperty.getContextPath());
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getPublicIp(), ipHelper.getServerPort(), mafProjectProperty.getContextPath());
}
}

This file was deleted.

Loading

0 comments on commit b6996c8

Please sign in to comment.