-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
prar
authored and
prar
committed
Aug 11, 2022
1 parent
fce6341
commit d99d6de
Showing
31 changed files
with
1,221 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
14
src/main/java/com/tc/execution/ExecutionApiApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/tc/execution/data/converters/ObjectToStringConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
Oops, something went wrong.