-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(jans-core): port Gluu ORM-based document store #2506 #2581
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions
20
...store/src/main/java/io/jans/service/document/store/conf/DBDocumentStoreConfiguration.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 io.jans.service.document.store.conf; | ||
|
||
import java.io.Serializable; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
/** | ||
* @author shekhar L. on 29/10/2022 | ||
*/ | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class DBDocumentStoreConfiguration implements Serializable { | ||
|
||
private static final long serialVersionUID = 3380170170265842538L; | ||
|
||
@Override | ||
public String toString() { | ||
return "DBDocumentStoreConfiguration []"; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -13,5 +13,5 @@ | |
*/ | ||
@XmlEnum(String.class) | ||
public enum DocumentStoreType { | ||
LOCAL, JCA, WEB_DAV | ||
LOCAL, JCA, WEB_DAV, DB | ||
} |
213 changes: 213 additions & 0 deletions
213
...-store/src/main/java/io/jans/service/document/store/provider/DBDocumentStoreProvider.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,213 @@ | ||
package io.jans.service.document.store.provider; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.Charset; | ||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.jans.orm.PersistenceEntryManager; | ||
import io.jans.service.document.store.conf.DBDocumentStoreConfiguration; | ||
import io.jans.service.document.store.conf.DocumentStoreConfiguration; | ||
import io.jans.service.document.store.conf.DocumentStoreType; | ||
import io.jans.service.document.store.service.DBDocumentService; | ||
import io.jans.service.document.store.service.OxDocument; | ||
import io.jans.util.StringHelper; | ||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
/** | ||
* @author Shekhar L. on 29/10/2022 | ||
*/ | ||
@ApplicationScoped | ||
public class DBDocumentStoreProvider extends DocumentStoreProvider<DBDocumentStoreProvider> { | ||
|
||
@Inject | ||
private Logger log; | ||
|
||
@Inject | ||
private DBDocumentService documentService; | ||
|
||
@Inject | ||
private DocumentStoreConfiguration documentStoreConfiguration; | ||
|
||
private DBDocumentStoreConfiguration dbDocumentStoreConfiguration; | ||
|
||
public DocumentStoreType getProviderType() { | ||
return DocumentStoreType.DB; | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
this.dbDocumentStoreConfiguration = documentStoreConfiguration.getDbConfiguration(); | ||
} | ||
|
||
public void configure(DocumentStoreConfiguration documentStoreConfiguration, PersistenceEntryManager persistenceEntryManager) { | ||
this.log = LoggerFactory.getLogger(DBDocumentStoreProvider.class); | ||
this.documentStoreConfiguration = documentStoreConfiguration; | ||
if(documentService == null) { | ||
this.documentService = new DBDocumentService(persistenceEntryManager); | ||
} | ||
} | ||
|
||
@Override | ||
public void create() { | ||
|
||
} | ||
|
||
@Override | ||
public void destroy() { | ||
|
||
} | ||
|
||
@Override | ||
public boolean hasDocument(String DisplayName) { | ||
log.debug("Has document: '{}'", DisplayName); | ||
if (StringHelper.isEmpty(DisplayName)) { | ||
throw new IllegalArgumentException("Specified path should not be empty!"); | ||
} | ||
OxDocument oxDocument = null; | ||
try { | ||
oxDocument = documentService.getOxDocumentByDisplayName(DisplayName); | ||
} catch (Exception e) { | ||
log.error("Failed to check if path '" + DisplayName + "' exists in repository", e); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean saveDocument(String name, String documentContent, Charset charset, List<String> moduleList) { | ||
log.debug("Save document: '{}'", name); | ||
OxDocument oxDocument = new OxDocument(); | ||
oxDocument.setDocument(documentContent); | ||
oxDocument.setDisplayName(name); | ||
try { | ||
try { | ||
oxDocument.setInum(documentService.generateInumForNewOxDocument()); | ||
String dn = "inum="+ oxDocument.getInum() +",ou=document,o=gluu"; | ||
oxDocument.setDn(dn); | ||
oxDocument.setDescription(name); | ||
oxDocument.setOxEnabled("true"); | ||
oxDocument.setOxModuleProperty(moduleList); | ||
documentService.addOxDocument(oxDocument); | ||
return true; | ||
} finally { | ||
} | ||
} catch (Exception ex) { | ||
log.error("Failed to write document to file '{}'", name, ex); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean saveDocumentStream(String name, InputStream documentStream, List <String> moduleList) { | ||
|
||
OxDocument oxDocument = new OxDocument(); | ||
oxDocument.setDisplayName(name); | ||
|
||
try { | ||
String documentContent = Base64.getEncoder().encodeToString(IOUtils.toByteArray(documentStream)); | ||
oxDocument.setDocument(documentContent); | ||
String inum = documentService.generateInumForNewOxDocument(); | ||
oxDocument.setInum(inum); | ||
String dn = "inum="+ oxDocument.getInum() +",ou=document,o=gluu"; | ||
oxDocument.setDn(dn); | ||
oxDocument.setDescription(name); | ||
oxDocument.setOxEnabled("true"); | ||
oxDocument.setOxModuleProperty(moduleList); | ||
documentService.addOxDocument(oxDocument); | ||
return true; | ||
} catch (IOException e) { | ||
log.error("Failed to write document from stream to file '{}'", name, e); | ||
}catch (Exception e) { | ||
log.error("Failed to write document from stream to file '{}'", name, e); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public String readDocument(String name, Charset charset) { | ||
log.debug("Read document: '{}'", name); | ||
OxDocument oxDocument; | ||
try { | ||
oxDocument = documentService.getOxDocumentByDisplayName(name); | ||
if(oxDocument != null) { | ||
return oxDocument.getDocument(); | ||
} | ||
} catch (Exception e) { | ||
log.error("Failed to read document as stream from file '{}'", name, e); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public InputStream readDocumentAsStream(String name) { | ||
log.debug("Read document as stream: '{}'", name); | ||
String filecontecnt = readDocument(name, null); | ||
if (filecontecnt == null) { | ||
log.error("Document file '{}' isn't exist", name); | ||
return null; | ||
} | ||
|
||
InputStream InputStream = new ByteArrayInputStream(Base64.getDecoder().decode(filecontecnt)); | ||
return InputStream; | ||
} | ||
|
||
@Override | ||
public boolean renameDocument(String currentDisplayName, String destinationDisplayName) { | ||
log.debug("Rename document: '{}' -> '{}'", currentDisplayName, destinationDisplayName); | ||
OxDocument oxDocument; | ||
try { | ||
oxDocument = documentService.getOxDocumentByDisplayName(currentDisplayName); | ||
if (oxDocument == null) { | ||
log.error("Document doesn't Exist with the name '{}'", currentDisplayName); | ||
return false; | ||
} | ||
oxDocument.setDisplayName(destinationDisplayName); | ||
documentService.updateOxDocument(oxDocument); | ||
OxDocument oxDocumentDestination = documentService.getOxDocumentByDisplayName(destinationDisplayName); | ||
if(oxDocumentDestination == null) { | ||
log.error("Failed to rename to destination file '{}'", destinationDisplayName); | ||
return false; | ||
} | ||
} catch (Exception e) { | ||
log.error("Failed to rename to destination file '{}'", destinationDisplayName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is wrong here. In case of exception, we got further in line 187 and return |
||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean removeDocument(String inum) { | ||
log.debug("Remove document: '{}'", inum); | ||
OxDocument oxDocument; | ||
try { | ||
oxDocument = documentService.getOxDocumentByInum(inum); | ||
if(oxDocument == null) { | ||
log.error(" document not exist file '{}'", inum); | ||
return false; | ||
} | ||
|
||
documentService.removeOxDocument(oxDocument); | ||
OxDocument checkOxDocument = documentService.getOxDocumentByInum(inum); | ||
if(checkOxDocument == null) { | ||
return true; | ||
} | ||
return false; | ||
} catch (Exception e) { | ||
log.error("Failed to remove document file '{}'", inum, e); | ||
} | ||
return false; | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOException is redundant because it has exactly same statements as super
Exception
.