CPD Results
The following document contains the results of PMD's CPD 6.13.0.
Duplications
| File |
Line |
| fr/paris/lutece/plugins/identitystore/v1/web/rs/swagger/SwaggerRest.java |
62 |
| fr/paris/lutece/plugins/identitystore/v2/web/rs/swagger/SwaggerRest.java |
62 |
@Path( RestConstants.BASE_PATH + Constants.API_PATH + Constants.VERSION_PATH )
public class SwaggerRest
{
private static final String BASE_INFOS_SCHEMES = "schemes";
private static final String BASE_INFOS_HOST = "host";
private static final String BASE_INFOS_BASE_PATH = "basePath";
/**
* Get Swagger.json
*
* @param request
* @param strVersion
* @return the swagger.json
* @throws java.net.MalformedURLException
* @throws java.io.IOException
*/
@GET
@Path( Constants.SWAGGER_PATH )
@Produces( MediaType.APPLICATION_JSON )
public Response getSwagger( @Context HttpServletRequest request, @PathParam( Constants.VERSION ) String strVersion )
throws MalformedURLException, IOException
{
File fileJson = new File( getJsonFilePath( strVersion ) );
if ( fileJson.exists( ) )
{
Map<String, String> mapBaseInfos = getBaseInfos( AppPathService.getBaseUrl( request ), strVersion );
ObjectMapper mapper = new ObjectMapper( );
ObjectNode objectNode = mapper.readValue( fileJson, ObjectNode.class );
if ( objectNode.path( BASE_INFOS_HOST ).isMissingNode( ) )
{
objectNode.put( BASE_INFOS_HOST, mapBaseInfos.get( BASE_INFOS_HOST ) );
}
if ( objectNode.path( BASE_INFOS_SCHEMES ).isMissingNode( ) )
{
objectNode.putArray( BASE_INFOS_SCHEMES ).add( mapBaseInfos.get( BASE_INFOS_SCHEMES ) );
}
if ( objectNode.path( BASE_INFOS_BASE_PATH ).isMissingNode( ) )
{
objectNode.put( BASE_INFOS_BASE_PATH, mapBaseInfos.get( BASE_INFOS_BASE_PATH ) );
}
String strSwaggerJson = mapper.writerWithDefaultPrettyPrinter( ).writeValueAsString( objectNode );
return Response.status( Response.Status.OK ).entity( strSwaggerJson ).build( );
}
AppLogService.error( Constants.ERROR_NOT_FOUND_RESOURCE );
return Response.status( Response.Status.NOT_FOUND )
.entity( JsonUtil.buildJsonResponse( new ErrorJsonResponse( Response.Status.NOT_FOUND.name( ), Constants.ERROR_NOT_FOUND_RESOURCE ) ) )
.build( );
}
/**
* Get the swagger.json file path
*
* @param strVersion
* @param strFileName
* @return
*/
private String getJsonFilePath( String strVersion )
{
return AppPathService.getWebAppPath( ) + Constants.SWAGGER_DIRECTORY_PATH + Constants.API_PATH + Constants.SWAGGER_PATH + Constants.SWAGGER_VERSION_PATH
+ strVersion + Constants.SWAGGER_JSON;
}
/**
* Get the base informations (host, scheme, baseUrl)
*
* @param strBaseUrl
* @param strVersion
* @return
* @throws MalformedURLException
*/
private Map<String, String> getBaseInfos( String strBaseUrl, String strVersion ) throws MalformedURLException
{
Map<String, String> map = new HashMap<>( );
URL url = new URL( strBaseUrl );
String strScheme = url.getProtocol( );
String strHost = url.getHost( );
String strBasePath = url.getPath( );
int nPort = url.getPort( );
if ( nPort != -1 )
{
strHost += ":" + nPort;
}
strBasePath = strBasePath + Constants.SWAGGER_REST_PATH + Constants.API_PATH + Constants.SWAGGER_VERSION_PATH + strVersion;
map.put( BASE_INFOS_SCHEMES, strScheme );
map.put( BASE_INFOS_HOST, strHost );
map.put( BASE_INFOS_BASE_PATH, strBasePath );
return map;
}
} |
| File |
Line |
| fr/paris/lutece/plugins/identitystore/v1/web/rs/IdentityStoreRestService.java |
57 |
| fr/paris/lutece/plugins/identitystore/v2/web/rs/IdentityStoreRestService.java |
57 |
@Path( RestConstants.BASE_PATH + Constants.PLUGIN_PATH + Constants.VERSION_PATH_V1 + Constants.IDENTITY_PATH )
public final class IdentityStoreRestService
{
private static final String ERROR_NO_IDENTITY_FOUND = "No identity found";
private static final String ERROR_NO_IDENTITY_TO_UPDATE = "no identity to update";
private static final String ERROR_DURING_TREATMENT = "An error occurred during the treatment.";
private final ObjectMapper _objectMapper;
/**
* private constructor
*/
public IdentityStoreRestService( )
{
_objectMapper = new ObjectMapper( );
_objectMapper.enable( SerializationFeature.INDENT_OUTPUT );
_objectMapper.enable( SerializationFeature.WRAP_ROOT_VALUE );
_objectMapper.enable( DeserializationFeature.UNWRAP_ROOT_VALUE );
_objectMapper.disable( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES );
}
/**
* Gives Identity from a connectionId or customerID either connectionId or customerId must be provided if connectionId AND customerId are provided, they
* must be consistent otherwise an AppException is thrown
*
* @param strConnectionId
* connection ID
* @param strCustomerId
* customerID
* @param strHeaderClientAppCode
* client code
* @param strQueryClientAppCode
* client code, will be removed, use Header parameter instead
* @return the identity
*/
@GET
@Produces( MediaType.APPLICATION_JSON )
public Response getIdentity( @QueryParam( Constants.PARAM_ID_CONNECTION ) String strConnectionId,
@QueryParam( Constants.PARAM_ID_CUSTOMER ) String strCustomerId, @HeaderParam( Constants.PARAM_CLIENT_CODE ) String strHeaderClientAppCode,
@QueryParam( Constants.PARAM_CLIENT_CODE ) String strQueryClientAppCode ) throws IdentityStoreException
{
String strClientAppCode = IdentityStoreService.getTrustedClientCode( strHeaderClientAppCode, strQueryClientAppCode );
try
{
IdentityStoreGetRequest identityStoreRequest = new IdentityStoreGetRequest( strConnectionId, strCustomerId, strClientAppCode, _objectMapper );
return Response.ok( identityStoreRequest.doRequest( ) ).build( );
}
catch( Exception exception )
{
return getErrorResponse( exception );
}
}
/**
* build error response from exception
*
* @param e
* exception
* @return ResponseDto from exception
*/
private Response getErrorResponse( Exception e ) |
| File |
Line |
| fr/paris/lutece/plugins/identitystore/v1/web/rs/IdentityStoreRestService.java |
125 |
| fr/paris/lutece/plugins/identitystore/v2/web/rs/IdentityStoreRestService.java |
125 |
if ( e instanceof IdentityNotFoundException )
{
strMessage = ERROR_NO_IDENTITY_FOUND;
status = Response.Status.NOT_FOUND;
}
else
{
strMessage = ERROR_DURING_TREATMENT;
status = Response.Status.BAD_REQUEST;
}
return buildResponse( strMessage, status );
}
/**
* Builds a {@code Response} object from the specified message and status
*
* @param strMessage
* the message
* @param status
* the status
* @return the {@code Response} object
*/
private Response buildResponse( String strMessage, Response.StatusType status )
{
try
{
ResponseDto response = new ResponseDto( );
response.setStatus( status.toString( ) );
response.setMessage( strMessage );
return Response.status( status ).type( MediaType.APPLICATION_JSON ).entity( _objectMapper.writeValueAsString( response ) ).build( );
}
catch( JsonProcessingException jpe )
{
return Response.status( status ).type( MediaType.TEXT_PLAIN ).entity( strMessage ).build( );
}
}
} |
| File |
Line |
| fr/paris/lutece/plugins/identitystore/v1/web/rs/swagger/Constants.java |
39 |
| fr/paris/lutece/plugins/identitystore/v2/web/rs/swagger/Constants.java |
39 |
public final class Constants
{
public static final String API_PATH = "identitystore/api";
public static final String VERSION_PATH = "/v{" + Constants.VERSION + "}";
public static final String ID_PATH = "/{" + Constants.ID + "}";
public static final String FILE_NAME_PATH = "/{" + Constants.FILE_NAME + ": .*\\.*}";
public static final String FILE_NAME = "filename";
public static final String VERSION = "version";
public static final String ID = "id";
public static final String SWAGGER_DIRECTORY_PATH = "/plugins/";
public static final String SWAGGER_PATH = "/swagger";
public static final String SWAGGER_VERSION_PATH = "/v";
public static final String SWAGGER_REST_PATH = "rest/";
public static final String SWAGGER_JSON = "/swagger.json";
public static final String EMPTY_OBJECT = "{}";
public static final String ERROR_NOT_FOUND_VERSION = "Version not found";
public static final String ERROR_NOT_FOUND_RESOURCE = "Resource not found";
public static final String ERROR_BAD_REQUEST_EMPTY_PARAMETER = "Empty parameter"; |
| File |
Line |
| fr/paris/lutece/plugins/identitystore/v1/web/request/IdentityStoreGetRequest.java |
82 |
| fr/paris/lutece/plugins/identitystore/v2/web/request/IdentityStoreGetRequest.java |
86 |
{
IdentityRequestValidator.instance( ).checkIdentity( _strConnectionId, _strCustomerId );
IdentityRequestValidator.instance( ).checkClientApplication( _strClientAppCode );
}
/**
* get the identity
*
* @throws IdentityStoreException
* if there is an exception during the treatment
*/
@Override
protected String doSpecificRequest( ) throws IdentityStoreException
{
final IdentitySearchResponse response = new IdentitySearchResponse( );
IdentityService.instance( ).search( _strCustomerId, _strConnectionId, response, _strClientAppCode, null );
if ( response.getIdentities( ) != null && !response.getIdentities( ).isEmpty( ) )
{
try
{
return _objectMapper.writeValueAsString( DtoConverter.convert( response.getIdentities( ).get( 0 ) ) );
}
catch( JsonProcessingException e )
{
throw new IdentityStoreException( ERROR_JSON_MAPPING, e );
}
}
return null;
}
} |