Skip to content

Commit

Permalink
feat(documentstore) : added new field jansFilePath to storing file-pa… (
Browse files Browse the repository at this point in the history
#8350)

* feat(documentstore) : added new field jansFilePath to storing file-path #8289

* feat(documentstore) : added new field jansFilePath #8289

* feat(documentstore) : updates for jansfilepath

---------

Co-authored-by: YuriyZ <[email protected]>
Co-authored-by: Yuriy Movchan <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2024
1 parent 0363fa8 commit cf875ec
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean hasDocument(String path) {
}
Document oxDocument = null;
try {
oxDocument = documentService.getDocumentByDisplayName(path);
oxDocument = documentService.getDocumentByJansFilePath(path);
if (oxDocument != null) {
return true;
}
Expand All @@ -96,6 +96,7 @@ public String saveDocument(String path, String description, String documentConte
Document oxDocument = new Document();
oxDocument.setDocument(documentContent);
oxDocument.setDisplayName(path);
oxDocument.setJansFilePath(path);
try {
oxDocument.setInum(documentService.generateInumForNewDocument());
String dn = "inum=" + oxDocument.getInum() + ",ou=document,o=jans";
Expand All @@ -116,6 +117,7 @@ public String saveDocumentStream(String path, String description, InputStream do

Document oxDocument = new Document();
oxDocument.setDisplayName(path);
oxDocument.setJansFilePath(path);

try {
String documentContent = new String(documentStream.readAllBytes(), StandardCharsets.UTF_8);
Expand Down Expand Up @@ -146,7 +148,7 @@ public String readDocument(String name, Charset charset) {
log.debug("Read document: '{}'", name);
Document oxDocument;
try {
oxDocument = documentService.getDocumentByDisplayName(name);
oxDocument = documentService.getDocumentByJansFilePath(name);
if (oxDocument != null) {
return oxDocument.getDocument();
}
Expand Down Expand Up @@ -180,14 +182,15 @@ public String renameDocument(String currentPath, String destinationPath) {
log.debug("Rename document: '{}' -> '{}'", currentPath, destinationPath);
Document oxDocument;
try {
oxDocument = documentService.getDocumentByDisplayName(currentPath);
oxDocument = documentService.getDocumentByJansFilePath(currentPath);
if (oxDocument == null) {
log.error("Document doesn't Exist with the name '{}'", currentPath);
return null;
}
oxDocument.setDisplayName(destinationPath);
oxDocument.setJansFilePath(destinationPath);
documentService.updateDocument(oxDocument);
Document oxDocumentDestination = documentService.getDocumentByDisplayName(destinationPath);
Document oxDocumentDestination = documentService.getDocumentByJansFilePath(destinationPath);
if (oxDocumentDestination == null) {
log.error("Failed to rename to destination file '{}'", destinationPath);
return null;
Expand All @@ -202,6 +205,23 @@ public String renameDocument(String currentPath, String destinationPath) {

@Override
public boolean removeDocument(String path) {
log.debug("Remove document: '{}'", path);
Document oxDocument;
try {
oxDocument = documentService.getDocumentByJansFilePath(path);
if (oxDocument == null) {
log.error(" document not exist file '{}'", path);
return false;
}
documentService.removeDocument(oxDocument);
return true;
} catch (Exception e) {
log.error("Failed to remove document file '{}'", path, e);
throw new DocumentException(e);
}
}

public boolean removeDocumentByDisplayName(String path) {
log.debug("Remove document: '{}'", path);
Document oxDocument;
try {
Expand All @@ -218,4 +238,44 @@ public boolean removeDocument(String path) {
}
}

public String renameDocumentByDisplayName(String currentPath, String destinationPath) {
log.debug("Rename document: '{}' -> '{}'", currentPath, destinationPath);
Document oxDocument;
try {
oxDocument = documentService.getDocumentByDisplayName(currentPath);
if (oxDocument == null) {
log.error("Document doesn't Exist with the name '{}'", currentPath);
return null;
}
oxDocument.setDisplayName(destinationPath);
oxDocument.setJansFilePath(destinationPath);
documentService.updateDocument(oxDocument);
Document oxDocumentDestination = documentService.getDocumentByDisplayName(destinationPath);
if (oxDocumentDestination == null) {
log.error("Failed to rename to destination file '{}'", destinationPath);
return null;
}
} catch (Exception e) {
log.error("Failed to rename to destination file '{}'", destinationPath);
throw new WriteDocumentException(e);
}

return destinationPath;
}

public String readDocumentByDisplayName(String filePath) {
log.debug("location of document: '{}'", filePath);
Document oxDocument;
try {
oxDocument = documentService.getDocumentByDisplayName(filePath);
if (oxDocument != null) {
return oxDocument.getDocument();
}
} catch (Exception e) {
log.error("Failed to location of document as stream from file path'{}'", filePath, e);
throw new DocumentException(e);
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public Document getDocumentByDn(String Dn) throws Exception {

/**
* Get documents by DisplayName
*
*
* @param DisplayName
* @return documents
*/
Expand All @@ -211,4 +211,21 @@ public Document getDocumentByDisplayName(String DisplayName) throws Exception {
}
return null;
}

/**
* Get documents by DisplayName
*
* @param DisplayName
* @return documents
*/
public Document getDocumentByJansFilePath(String filePath) throws Exception {
Document document = new Document();
document.setJansFilePath(filePath);
document.setDn(getDnForDocument(null));;
List<Document> documents = persistenceEntryManager.findEntries(document);
if ((documents != null) && (documents.size() > 0)) {
return documents.get(0);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class Document extends Entry implements Serializable {

@AttributeName
private Date creationDate;

@AttributeName
private String jansFilePath;

@AttributeName
private List<String> jansModuleProperty;
Expand Down Expand Up @@ -147,11 +150,19 @@ public void setJansAlias(String jansAlias) {
this.jansAlias = jansAlias;
}

public String getJansFilePath() {
return jansFilePath;
}

public void setJansFilePath(String jansFilePath) {
this.jansFilePath = jansFilePath;
}

@Override
public String toString() {
return "Document [inum=" + inum + ", displayName=" + displayName + ", description=" + description
+ ", document=" + document + ", creationDate=" + creationDate + ", jansModuleProperty="
+ jansModuleProperty + ", jansLevel=" + jansLevel + ", jansRevision=" + jansRevision + ", jansEnabled="
+ jansEnabled + ", jansAlias=" + jansAlias + "]";
+ jansEnabled + ", jansAlias=" + jansAlias + " jansFilePath=" + jansFilePath + "]";
}
}
14 changes: 13 additions & 1 deletion jans-linux-setup/jans_setup/schema/jans_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3221,6 +3221,17 @@
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"x_origin": "Jans created attribute"
},
{
"desc": "Save Document file path in DB",
"equality": "caseIgnoreMatch",
"names": [
"jansFilePath"
],
"oid": "jansAttr",
"substr": "caseIgnoreSubstringsMatch",
"syntax": "1.3.6.1.4.1.1466.115.121.1.15",
"x_origin": "Jans created attribute"
},
{
"desc": "Transpiled code of an agama flow",
"equality": "caseIgnoreMatch",
Expand Down Expand Up @@ -5035,7 +5046,8 @@
"jansLevel",
"jansRevision",
"jansEnabled",
"jansAlias"
"jansAlias",
"jansFilePath"
],
"must": [
"objectclass"
Expand Down
14 changes: 14 additions & 0 deletions jans-linux-setup/jans_setup/static/rdbm/sql_data_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1039,5 +1039,19 @@
"spanner": {
"type": "STRING(MAX)"
}
},
"jansFilePath": {
"mysql": {
"size": 128,
"type": "VARCHAR"
},
"pgsql": {
"size": 128,
"type": "VARCHAR"
},
"spanner": {
"size": 128,
"type": "STRING"
}
}
}

0 comments on commit cf875ec

Please sign in to comment.