Skip to content

Commit

Permalink
resolve formating issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chopadetejaswini committed Oct 10, 2023
1 parent 047e438 commit b4a6861
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 45 deletions.
7 changes: 2 additions & 5 deletions java/pojos/src/main/java/dev/sunbirdrc/pojos/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,12 @@ public enum API_ID {
HEALTH(getApiPrefix() + ".health"),
DELETE(getApiPrefix() + ".delete"),

PUT(getApiPrefix() + ".put"),

POST(getApiPrefix() + ".post"),

GET(getApiPrefix() + ".get"),

PATCH(getApiPrefix() + ".patch"),
PUT(getApiPrefix() + ".put"),
SEARCH(getApiPrefix() + ".search"),

POST(getApiPrefix() + ".post"),
SIGN(getApiName() + ".utils.sign"),
VERIFY(getApiName() + ".utils.verify"),
KEYS(getApiName() + ".utils.keys"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import dev.sunbirdrc.registry.transform.Configuration;
import dev.sunbirdrc.registry.transform.Data;
import dev.sunbirdrc.registry.transform.ITransformer;
import dev.sunbirdrc.registry.util.EntityParenter;
import dev.sunbirdrc.registry.util.ViewTemplateManager;
import dev.sunbirdrc.validators.ValidationException;
import org.agrona.Strings;
Expand Down Expand Up @@ -74,10 +73,6 @@ public class RegistryEntityController extends AbstractController {
@Value("${certificate.enableExternalTemplates:false}")
boolean externalTemplatesEnabled;

@Autowired
EntityParenter entityParenter;


@RequestMapping(value = "/api/v1/{entityName}/invite", method = RequestMethod.POST)
public ResponseEntity<Object> invite(
@PathVariable String entityName,
Expand Down Expand Up @@ -170,6 +165,7 @@ public ResponseEntity<Object> deleteEntity(
responseParams.setStatus(Response.Status.SUCCESSFUL);
watch.stop(tag);
return new ResponseEntity<>(response, HttpStatus.OK);

} catch (RecordNotFoundException e) {
createSchemaNotFoundResponse(e.getMessage(), responseParams);
response = new Response(Response.API_ID.DELETE, "ERROR", responseParams);
Expand Down Expand Up @@ -260,8 +256,9 @@ public ResponseEntity<Object> putEntity(
watch.stop(tag);

return new ResponseEntity<>(response, HttpStatus.OK);

} catch (RecordNotFoundException e) {
createSchemaNotFoundResponse(e.getMessage(), responseParams);
createSchemaNotFoundResponse(e.getMessage(), responseParams);
response = new Response(Response.API_ID.PUT, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
Expand Down Expand Up @@ -311,7 +308,7 @@ public ResponseEntity<Object> postEntity(

return new ResponseEntity<>(response, HttpStatus.OK);
} catch (RecordNotFoundException e) {
createSchemaNotFoundResponse(e.getMessage(), responseParams);
createSchemaNotFoundResponse(e.getMessage(), responseParams);
response = new Response(Response.API_ID.POST, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (MiddlewareHaltException e) {
Expand Down Expand Up @@ -363,7 +360,7 @@ public ResponseEntity<Object> updatePropertyOfTheEntity(
watch.stop(tag);
return new ResponseEntity<>(response, HttpStatus.OK);
} catch (RecordNotFoundException e) {
createSchemaNotFoundResponse(e.getMessage(), responseParams);
createSchemaNotFoundResponse(e.getMessage(), responseParams);
response = new Response(Response.API_ID.PUT, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
Expand All @@ -387,13 +384,15 @@ public ResponseEntity<Object> addNewPropertyToTheEntity(
checkEntityNameInDefinitionManager(entityName);
registryHelper.authorize(entityName, entityId, request);
} catch (RecordNotFoundException e) {
createSchemaNotFoundResponse(e.getMessage(), responseParams);
response = new Response(Response.API_ID.POST, "ERROR", responseParams);
createSchemaNotFoundResponse(e.getMessage(), responseParams);
response = new Response(Response.API_ID.POST, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
return createUnauthorizedExceptionResponse(e);
}

try {

String tag = "RegistryController.addNewPropertyToTheEntity " + entityName;
watch.start(tag);
String notes = getNotes(requestBody);
Expand Down Expand Up @@ -462,8 +461,8 @@ public ResponseEntity<Object> getEntityWithConsent(
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (RecordNotFoundException e) {
createSchemaNotFoundResponse(e.getMessage(), responseParams);
Response response = new Response(Response.API_ID.GET, "ERROR", responseParams);
createSchemaNotFoundResponse(e.getMessage(), responseParams);
Response response = new Response(Response.API_ID.GET, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
logger.error("Error in partner api access", e);
Expand Down Expand Up @@ -500,8 +499,10 @@ private ArrayList<String> getConsentFields(HttpServletRequest request) {
{MediaType.APPLICATION_PDF_VALUE, MediaType.TEXT_HTML_VALUE, Constants.SVG_MEDIA_TYPE})
public ResponseEntity<Object> getEntityType(@PathVariable String entityName,
@PathVariable String entityId,
HttpServletRequest request, @RequestHeader(required = false) String viewTemplateId) {
HttpServletRequest request,
@RequestHeader(required = false) String viewTemplateId) {
ResponseParams responseParams = new ResponseParams();
Response response ;
if (registryHelper.doesEntityOperationRequireAuthorization(entityName) && securityEnabled) {
try {

Expand All @@ -511,9 +512,9 @@ public ResponseEntity<Object> getEntityType(@PathVariable String entityName,
checkEntityNameInDefinitionManager(entityName);
registryHelper.authorizeAttestor(entityName, request);
} catch (RecordNotFoundException re) {
createSchemaNotFoundResponse(re.getMessage(), responseParams);
Response response = new Response(Response.API_ID.GET, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
createSchemaNotFoundResponse(re.getMessage(), responseParams);
response = new Response(Response.API_ID.GET, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception exceptionFromAuthorizeAttestor) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
Expand Down Expand Up @@ -604,7 +605,7 @@ public ResponseEntity<Object> getEntity(
return new ResponseEntity<>(node, HttpStatus.OK);

} catch (RecordNotFoundException re) {
createSchemaNotFoundResponse(re.getMessage(), responseParams);
createSchemaNotFoundResponse(re.getMessage(), responseParams);
response = new Response(Response.API_ID.GET, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
Expand Down Expand Up @@ -664,7 +665,7 @@ public ResponseEntity<Object> getEntityByToken(@PathVariable String entityName,
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
}
} catch (RecordNotFoundException e) {
createSchemaNotFoundResponse(e.getMessage(), responseParams);
createSchemaNotFoundResponse(e.getMessage(),responseParams);
response = new Response(Response.API_ID.GET, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
Expand All @@ -682,7 +683,7 @@ public ResponseEntity<Object> getEntityForAttestation(
@PathVariable String entity,
@PathVariable String entityId
) {
ResponseParams responseParams = new ResponseParams();
ResponseParams responseParams = new ResponseParams();
try {
JsonNode resultNode = registryHelper.readEntity("", entity, entityId, false, null, false);
ObjectNode objectNode = objectMapper.createObjectNode();
Expand All @@ -693,11 +694,13 @@ public ResponseEntity<Object> getEntityForAttestation(
.getAttestationPolicies();
objectNode.set("attestationPolicies", objectMapper.convertValue(attestationPolicies, JsonNode.class));
return new ResponseEntity<>(objectNode, HttpStatus.OK);

} catch (RecordNotFoundException re) {
createSchemaNotFoundResponse(re.getMessage(), responseParams);
createSchemaNotFoundResponse(re.getMessage(), responseParams);
Response response = new Response(Response.API_ID.GET, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
}
catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand All @@ -716,10 +719,11 @@ public ResponseEntity<Object> attestEntity(
try {
checkEntityNameInDefinitionManager(entityName);
} catch (RecordNotFoundException re) {
createSchemaNotFoundResponse(re.getMessage(), responseParams);
createSchemaNotFoundResponse(re.getMessage(),responseParams);
Response response = new Response(Response.API_ID.PATCH, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
}

logger.info("Attestation request for {}", rootNode.get("fieldPaths"));
JsonNode nodePath = rootNode.get("jsonPaths");
if (nodePath instanceof ArrayNode) {
Expand Down Expand Up @@ -807,7 +811,7 @@ public ResponseEntity<Object> getSignedEntityByToken(@PathVariable String entity
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
}
} catch (RecordNotFoundException re) {
createSchemaNotFoundResponse(re.getMessage(), responseParams);
createSchemaNotFoundResponse(re.getMessage(), responseParams);
response = new Response(Response.API_ID.GET, "ERROR", responseParams);
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
} catch (Exception e) {
Expand Down Expand Up @@ -837,6 +841,7 @@ public ResponseEntity<Object> getAttestationCertificate(HttpServletRequest reque
getTemplateUrlFromRequest(request, entityName),
getAttestationNode(attestationId, node)
), HttpStatus.OK);

} catch (RecordNotFoundException re) {
createSchemaNotFoundResponse(re.getMessage(), responseParams);
Response response = new Response(Response.API_ID.GET, "ERROR", responseParams);
Expand All @@ -853,16 +858,15 @@ public ResponseEntity<Object> getAttestationCertificate(HttpServletRequest reque
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}

@RequestMapping(value = "/api/v1/{entityName}/{entityId}/revoke", method = RequestMethod.POST)
public ResponseEntity<Object> revokeACredential(
public ResponseEntity<Object> revokeACredential (
HttpServletRequest request,
@PathVariable String entityName,
@PathVariable String entityId,
@RequestHeader HttpHeaders headers
) {
){
String userId = USER_ANONYMOUS;
logger.info("Revoking the entityType {} with {} Id", entityName, entityId);
logger.info("Revoking the entityType {} with {} Id",entityName, entityId);
// Check fot Authorisation
if (registryHelper.doesEntityOperationRequireAuthorization(entityName)) {
try {
Expand All @@ -876,12 +880,12 @@ public ResponseEntity<Object> revokeACredential(
try {
String tag = "RegistryController.revokeAnExistingCredential " + entityName;
watch.start(tag);
JsonNode existingEntityNode = getEntityJsonNode(entityName, entityId, false, userId, null);
JsonNode existingEntityNode = getEntityJsonNode(entityName, entityId,false, userId, null);
String signedData = existingEntityNode.get(OSSystemFields._osSignedData.name()).asText();
if (signedData.equals(new String()) || signedData.equals(null)) {
throw new RecordNotFoundException("Credential is already revoked");
}
JsonNode revokedEntity = registryHelper.revokeAnEntity(entityName, entityId, userId, existingEntityNode);
JsonNode revokedEntity = registryHelper.revokeAnEntity( entityName ,entityId, userId, existingEntityNode);
if (revokedEntity != null) {
registryHelper.revokeExistingCredentials(entityName, entityId, userId, signedData);
}
Expand All @@ -893,7 +897,7 @@ public ResponseEntity<Object> revokeACredential(
logger.error("Registry Controller: Exception while revoking an entity:", e);
responseParams.setStatus(Response.Status.UNSUCCESSFUL);
responseParams.setErrmsg(e.getMessage());
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(response,HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,38 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import dev.sunbirdrc.pojos.AsyncRequest;
import dev.sunbirdrc.pojos.SunbirdRCInstrumentation;
import org.mockito.ArgumentMatchers;
import dev.sunbirdrc.registry.exception.RecordNotFoundException;
import dev.sunbirdrc.registry.helper.RegistryHelper;
import dev.sunbirdrc.registry.model.DBConnectionInfoMgr;
import dev.sunbirdrc.registry.service.FileStorageService;
import dev.sunbirdrc.registry.service.ICertificateService;
import dev.sunbirdrc.registry.transform.*;
import dev.sunbirdrc.registry.util.DefinitionsManager;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import dev.sunbirdrc.registry.util.ViewTemplateManager;
import dev.sunbirdrc.registry.util.EntityParenter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import org.springframework.http.HttpHeaders;
import javax.servlet.http.HttpServletRequest;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@WebMvcTest({RegistryEntityController.class})
Expand Down Expand Up @@ -77,9 +74,6 @@ public class RegistryEntityControllerTest {
@MockBean
private ViewTemplateManager viewTemplateManager;

@MockBean
private EntityParenter entityParenter;

@Before
public void setUp() {
abstractController = new RegistryEntityController();
Expand Down

0 comments on commit b4a6861

Please sign in to comment.