-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from tejash-jl/schemaAPI
added functionality to support dynamic schemas
- Loading branch information
Showing
26 changed files
with
777 additions
and
70 deletions.
There are no files selected for viewing
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
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
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
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
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,11 @@ | ||
server.port=8082 | ||
|
||
spring.datasource.url=${connectionInfo_uri:jdbc:postgresql://0.0.0.0:5432/registry} | ||
spring.datasource.username=${connectionInfo_username:postgres} | ||
spring.datasource.password=${connectionInfo_password:postgres} | ||
|
||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.hibernate.ddl-auto=update | ||
|
||
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true | ||
sunbirdrc.url=${sunbirdrc_url:http://localhost:8081} |
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
20 changes: 20 additions & 0 deletions
20
java/middleware-commons/src/main/java/dev/sunbirdrc/registry/middleware/util/Did.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,20 @@ | ||
package dev.sunbirdrc.registry.middleware.util; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class Did { | ||
private String method; | ||
private String methodIdentifier; | ||
|
||
public static Did parse(String didText) throws Exception { | ||
String[] split = didText.split(":"); | ||
if (split.length == 3) { | ||
return Did.builder().method(split[1]).methodIdentifier(split[2]).build(); | ||
} else { | ||
throw new Exception("Invalid Did Format: " + didText); | ||
} | ||
} | ||
} |
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
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
51 changes: 51 additions & 0 deletions
51
java/registry/src/main/java/dev/sunbirdrc/registry/config/SchemaLoader.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,51 @@ | ||
package dev.sunbirdrc.registry.config; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import dev.sunbirdrc.pojos.APIMessage; | ||
import dev.sunbirdrc.registry.service.ISearchService; | ||
import dev.sunbirdrc.registry.util.DefinitionsManager; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
|
||
import static dev.sunbirdrc.registry.Constants.Schema; | ||
|
||
@Component | ||
public class SchemaLoader implements ApplicationListener<ContextRefreshedEvent> { | ||
public static final Logger logger = LoggerFactory.getLogger(SchemaLoader.class); | ||
|
||
@Autowired | ||
private ISearchService searchService; | ||
|
||
@Autowired | ||
private DefinitionsManager definitionsManager; | ||
|
||
@Override | ||
public void onApplicationEvent(@NotNull ContextRefreshedEvent contextRefreshedEvent) { | ||
loadSchemasFromDB(); | ||
} | ||
|
||
private void loadSchemasFromDB() { | ||
ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); | ||
objectNode.set("entityType", JsonNodeFactory.instance.arrayNode().add(Schema)); | ||
objectNode.set("filters", JsonNodeFactory.instance.objectNode()); | ||
try { | ||
JsonNode searchResults = searchService.search(objectNode); | ||
searchResults.get(Schema).forEach(schemaNode -> { | ||
definitionsManager.appendNewDefinition(schemaNode.get(Schema.toLowerCase())); | ||
}); | ||
logger.info("Loaded {} schema from DB", searchResults.get(Schema).size()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.