Skip to content

Commit

Permalink
template init
Browse files Browse the repository at this point in the history
  • Loading branch information
prar authored and prar committed Aug 11, 2022
1 parent fce6341 commit d99d6de
Show file tree
Hide file tree
Showing 31 changed files with 1,221 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added screenshots/code-coverage-report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/surefire-report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/main/java/com/tc/execution/ExecutionApiApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tc.execution;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@Configuration
public class ExecutionApiApplication {
public static void main(final String[] args) {
SpringApplication.run(ExecutionApiApplication.class, args);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/tc/execution/api/EchoController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tc.execution.api;

import org.springframework.stereotype.Controller;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Controller
@Path("/v1/echo")
public class EchoController {
@GET
@Path("/{text}")
public Response echo(@PathParam("text") String text) {
return Response.ok(text).build();
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/tc/execution/api/JerseyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.tc.execution.api;

import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
import io.swagger.jaxrs.listing.SwaggerSerializers;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.annotation.PostConstruct;

@Configuration
@Primary
public class JerseyConfig extends ResourceConfig {

@PostConstruct
public void init() {
registerEndpoints();
configureSwagger();
property(ServletProperties.FILTER_FORWARD_ON_404, true);
}
private void registerEndpoints() {
register(EchoController.class);
register(NumberController.class);
register(SeriesController.class);
register(SipTestParametersController.class);
register(CustomerController.class);
register(SubscriptionController.class);
register(NotificationController.class);
register(OperatorConsentController.class);
}

public void configureSwagger() {
this.register(ApiListingResource.class);
this.register(SwaggerSerializers.class);
BeanConfig config = new BeanConfig();
config.setConfigId("execution-api");
config.setTitle("execution-api");
config.setVersion("1.0");
config.setBasePath("/execution");
config.setResourcePackage("com.tc.execution");
config.setScan(true);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/tc/execution/data/DozerMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tc.execution.data;

import org.springframework.data.domain.Page;

import java.util.List;

public interface DozerMapper {
<T> T create(Class<T> target, Object source);

<T> T create(Class<T> target, Object source, String mappingId);

<T, S> List<T> createList(Class<T> target, Iterable<S> source);

<T, S> List<T> createList(Class<T> target, Iterable<S> source, String mappingId);


void transfer(Object source, Object target);
}
62 changes: 62 additions & 0 deletions src/main/java/com/tc/execution/data/DozerMapperBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.tc.execution.data;
import com.tc.oc.common.models.Range;
import org.dozer.DozerBeanMapper;
import org.dozer.DozerBeanMapperBuilder;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@Component
public class DozerMapperBean implements DozerMapper {
private DozerBeanMapper mapper;

public DozerMapperBean() {
mapper = (DozerBeanMapper) DozerBeanMapperBuilder.create().build();
}

@Override
public final <T> T create(final Class<T> target, final Object source) {
return this.create(target, source, null);
}


@Override
public final <T> T create(final Class<T> target, final Object source, final String mappingId) {
if (source == null) {
return null;
}
T result;
if (mappingId != null) {
result = mapper.map(source, target, mappingId);
} else {
result = mapper.map(source, target);
}
return result;
}

@Override
public final <T, S> List<T> createList(final Class<T> target, final Iterable<S> source) {
return createList(target, source, null);
}

@Override
public final <T, S> List<T> createList(final Class<T> target, final Iterable<S> source, final String mappingId) {
return StreamSupport.stream(source.spliterator(), false).map(o -> create(target, o, mappingId))
.collect(Collectors.toList());
}




@Override
public final void transfer(final Object source, final Object target) {
mapper.map(source, target);
}

public final DozerBeanMapper getMapper() {
return this.mapper;
}
}
81 changes: 81 additions & 0 deletions src/main/java/com/tc/execution/data/JsonMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.tc.execution.data;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;

@Service
public class JsonMapper {

private static final Logger LOG = LoggerFactory.getLogger(JsonMapper.class);
private static final ObjectMapper objectMapper;
static {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);

}


public JsonMapper(){}

public <T> T fromJsonWithOutAnnotation(String json, TypeReference<T> type) {
try {
objectMapper.configure(MapperFeature.USE_ANNOTATIONS, false);
T t = (T) objectMapper.readValue(json, type);
objectMapper.configure(MapperFeature.USE_ANNOTATIONS, true);
return t;
} catch (IOException e){
LOG.error("unable to parse json String {}",json);
throw new RuntimeException(e);
}

}
public <T> T fromJson(String json, TypeReference<T> type) {
try {
return (T) objectMapper.readValue(json, type);
} catch (IOException e){
LOG.error("unable to parse json String {}",json);
throw new RuntimeException(e);
}

}

public <T> T fromJson(String json, Class<T> type) {
try {
return objectMapper.readValue(json, type);
} catch (IOException e) {
LOG.error("Failed to map data from json",e);
return null;
}
}

public <T> T fromJsonFile(File file, TypeReference<T> t) {
try {
return (T) objectMapper.readValue(file,t);
} catch (IOException e) {
LOG.error("unable to parse json String {}",file);
throw new RuntimeException(e);

}
}

public String toJson(Object object) {
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.tc.execution.data.converters;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tc.oc.common.models.notification.DataDTO;
import org.dozer.CustomConverter;

public class ObjectToStringConverter implements CustomConverter {

@Override
public String convert(Object destinationFieldValue, Object sourceFieldValue, Class<?> destinationClass,
Class<?> sourceClass) {
if(sourceFieldValue == null) {
return null;
}
if (sourceClass.equals(DataDTO.class)) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.writeValueAsString(sourceFieldValue);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
return null;
}
}

Loading

0 comments on commit d99d6de

Please sign in to comment.