Skip to content
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(config-api): asset mgt changes to use document service rather than provider #8324

Merged
merged 18 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a564917
fix: user mgt error for jansStatus issue#8258
pujavs Apr 11, 2024
be5d077
fix: user mgt error for jansStatus issue#8258
pujavs Apr 11, 2024
758dd0e
fix: user mgt error for jansStatus issue#8258
pujavs Apr 11, 2024
d59c57f
Merge branch 'main' of https://github.com/JanssenProject/jans into ja…
pujavs Apr 12, 2024
59de1e2
feat(config-api): create client and attribute test change
pujavs Apr 12, 2024
d08dcdb
Merge branch 'main' of https://github.com/JanssenProject/jans into ja…
pujavs Apr 12, 2024
cdfaed2
fix(config-api): fix attribute validation while update issue#8291
pujavs Apr 12, 2024
602c16e
fix(config-api): fix attribute validation while update issue#8291
pujavs Apr 12, 2024
10ea80b
Merge branch 'main' of https://github.com/JanssenProject/jans into ja…
pujavs Apr 13, 2024
2cbe491
fix(config-api): user status field changes
pujavs Apr 13, 2024
40a2f46
Merge branch 'main' of https://github.com/JanssenProject/jans into ja…
pujavs Apr 16, 2024
f511eea
fix(config-api): asset mgt changes to use document service rather tha…
pujavs Apr 16, 2024
7133dc4
feat(config-api): sync with main
pujavs Apr 17, 2024
553aea5
Merge branch 'main' of https://github.com/JanssenProject/jans into ja…
pujavs Apr 18, 2024
f52745a
fix(config-api): input stram handling
pujavs Apr 18, 2024
ba16744
Merge branch 'main' of https://github.com/JanssenProject/jans into ja…
pujavs Apr 19, 2024
48659e4
fix(config-api): stream handling
pujavs Apr 19, 2024
1cee78f
Merge branch 'main' into jans-config-fixes
yuriyz Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions jans-config-api/docs/jans-config-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8217,21 +8217,21 @@ components:
$ref: '#/components/schemas/AttributeValidation'
tooltip:
type: string
selected:
type: boolean
adminCanAccess:
userCanView:
type: boolean
adminCanView:
type: boolean
adminCanEdit:
type: boolean
userCanEdit:
type: boolean
userCanAccess:
type: boolean
userCanView:
adminCanAccess:
type: boolean
whitePagesCanView:
selected:
type: boolean
userCanEdit:
whitePagesCanView:
type: boolean
baseDn:
type: string
Expand Down Expand Up @@ -8650,6 +8650,10 @@ components:
type: boolean
useHighestLevelScriptIfAcrScriptNotFound:
type: boolean
acrMappings:
type: object
additionalProperties:
type: string
authenticationFiltersEnabled:
type: boolean
clientAuthenticationFiltersEnabled:
Expand Down Expand Up @@ -9830,10 +9834,10 @@ components:
type: array
items:
type: object
displayValue:
type: string
value:
type: object
displayValue:
type: string
LocalizedString:
type: object
properties:
Expand Down Expand Up @@ -10519,10 +10523,10 @@ components:
ttl:
type: integer
format: int32
persisted:
type: boolean
opbrowserState:
type: string
persisted:
type: boolean
SessionIdAccessMap:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.jans.util.exception.InvalidAttributeException;
import io.jans.util.exception.InvalidConfigurationException;
import io.jans.service.document.store.service.DocumentStoreService;
import io.jans.service.document.store.service.LocalDocumentStoreService;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -38,6 +37,7 @@
import jakarta.inject.Named;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.WebApplicationException;
import org.apache.commons.codec.binary.Base64InputStream;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;

Expand All @@ -54,17 +54,14 @@ public class AssetService {
@Inject
AuthUtil authUtil;

@Inject
DocumentStoreService documentStoreService;

@Inject
DBDocumentStoreProvider dBDocumentStoreProvider;

@Inject
DBDocumentService dbDocumentService;
DocumentStoreService documentStoreService;

@Inject
private LocalDocumentStoreService localDocumentStoreService;
DBDocumentService dbDocumentService;

public String getDnForAsset(String inum) throws Exception {
return dbDocumentService.getDnForDocument(inum);
Expand Down Expand Up @@ -134,12 +131,12 @@ public List<Document> getAssetByName(String name) throws Exception {
log.info("Get asset by name:{}", name);
Filter nameFilter = Filter.createEqualityFilter(AttributeConstants.DISPLAY_NAME, name);
List<Document> documents = persistenceEntryManager.findEntries(getDnForAsset(null), Document.class, nameFilter);
log.info("Asset by name:{} are documents:{}", name, documents);
log.trace("Asset by name:{} are documents:{}", name, documents);
return documents;
}

public Document saveAsset(Document asset, InputStream documentStream) throws Exception {
log.info("Save new asset - asset:{}, documentStream:{}", asset, documentStream);
log.info("Save asset - asset:{}, documentStream:{}", asset, documentStream);

if (asset == null) {
throw new InvalidAttributeException("Asset object is null!!!");
Expand All @@ -152,30 +149,36 @@ public Document saveAsset(Document asset, InputStream documentStream) throws Exc
ByteArrayOutputStream bos = getByteArrayOutputStream(documentStream);
log.trace("Asset ByteArrayOutputStream :{}", bos);

// update asset revision
updateRevision(asset);

//get asset
try (InputStream is = new Base64InputStream(getInputStream(bos), true)) {
asset = setAssetContent(asset, is);
}
// save asset in DB store
if (StringUtils.isBlank(asset.getInum())) {
log.info("As inum is blank create new asset :{}", asset);
saveNewAsset(asset, getInputStream(bos));
String inum = asset.getInum();
log.trace("inum of asset to be saved is:{}", inum);
if (StringUtils.isBlank(inum)) {
inum = dbDocumentService.generateInumForNewDocument();
asset.setInum(inum);
String dn = "inum=" + asset.getInum() + ",ou=document,o=jans";
asset.setDn(dn);
log.info("As inum is blank create new asset with inum:{}", inum);
dbDocumentService.addDocument(asset);
} else {
log.info("Inum is not blank hence update existing asset :{}", asset);
asset = updateAsset(asset, getInputStream(bos));
log.info("Inum is not blank hence update existing asset with inum :{}", inum);
dbDocumentService.updateDocument(asset);
}
log.debug("Saved asset is :{}", asset);

// copy asset on jans-server
String result = copyAssetOnServer(asset, getInputStream(bos));
log.info("Result of asset saved on server :{}", result);
try (InputStream ins = getInputStream(bos)) {
String result = copyAssetOnServer(asset, ins);
log.info("Result of asset saved on server :{}", result);
}


// Get final asset
List<Document >assets = this.getAssetByName(asset.getDisplayName());
if(assets==null) {
throw new WebApplicationException(" Could not save asset");
}
asset = assets.get(0);
log.info("\n * Asset saved :{}", asset);
asset = this.getAssetByInum(asset.getInum());

log.info("\n * Asset successfully saved :{}", asset);
return asset;
}

Expand All @@ -192,15 +195,15 @@ public boolean removeAsset(String inum) throws Exception {
// remove asset from DB store
dbDocumentService.removeDocument(asset);
log.info("Deleted asset identified by inum {}", inum);

// remove asset from server
boolean status = deleteAssetFromServer(asset);
log.info("Status on deleting asset from server is:{}", status);
if(!status) {
log.error("Could not remove asset from server identified by inum:{}",inum);
throw new WebApplicationException("Could not delete asset identified by inum - "+inum);
if (!status) {
log.error("Could not remove asset from server identified by inum:{}", inum);
throw new WebApplicationException("Could not delete asset identified by inum - " + inum);
}

return status;
}

Expand All @@ -222,8 +225,7 @@ public InputStream readAssetStream(String assetName) throws Exception {
Document asset = assets.get(0);
String assetPath = asset.getDescription();
filePath = assetPath + File.separator + assetName;
log.info("documentStoreService:{}, filePath:{}, localDocumentStoreService:{} ", documentStoreService, filePath,
localDocumentStoreService);
log.info("documentStoreService:{}, filePath:{}", documentStoreService, filePath);

InputStream stream = dBDocumentStoreProvider.readDocumentAsStream(filePath);
log.info("Read asset stream:{}", stream);
Expand All @@ -232,24 +234,23 @@ public InputStream readAssetStream(String assetName) throws Exception {

}

private Document updateAsset(Document asset, InputStream documentStream) throws Exception {
log.info("Update an asset - asset:{}, documentStream:{}", asset, documentStream);
private Document setAssetContent(Document asset, InputStream documentStream) throws Exception {
log.info(" an asset - asset:{}, documentStream:{}", asset, documentStream);
if (asset == null) {
throw new InvalidAttributeException(" Asset object is null!!!");
}

if (documentStream == null) {
throw new InvalidAttributeException(" Asset data stream object is null!!!");
throw new InvalidAttributeException(" Asset data stream is null!!!");
}

String documentContent = new String(documentStream.readAllBytes(), StandardCharsets.UTF_8);
asset.setDocument(documentContent);
dbDocumentService.updateDocument(asset);

// Get final asset
asset = dbDocumentService.getDocumentByInum(asset.getInum());
// update asset revision
updateRevision(asset);

log.info("\n * Successfully updated asset:{}", asset);
log.info("\n * Successfully updated asset");
return asset;
}

Expand Down Expand Up @@ -278,15 +279,14 @@ private boolean deleteAssetFromServer(Document asset) {
}

String filePath = path + File.separator + fileName;
log.info("documentStoreService:{}, localDocumentStoreService:{}, filePath:{} ", documentStoreService,
localDocumentStoreService, filePath);
log.info("documentStoreService:{}, filePath:{} ", documentStoreService, filePath);
deleteStatus = documentStoreService.removeDocument(filePath);
log.info("Asset deletion status:{}", deleteStatus);
return deleteStatus;
}

private Document updateRevision(Document asset) {
log.info("Update asset revision - asset:{}", asset);
log.debug("Update asset revision - asset:{}", asset);
try {
if (asset == null) {
return asset;
Expand All @@ -301,22 +301,14 @@ private Document updateRevision(Document asset) {
}
revision = String.valueOf(intRevision);
asset.setJansRevision(revision);
log.info("Updated asset revision - asset:{}", asset);
log.info("Updated asset revision to asset.getJansRevision():{}", asset.getJansRevision());
} catch (Exception ex) {
log.error("Exception while updating asset revision is - ", ex);
return asset;
}
return asset;
}

private Document saveNewAsset(Document asset, InputStream stream) {
log.info("Saving new asset in DB DocumentStore - asset:{}, stream:{}", asset, stream);
String path = dBDocumentStoreProvider.saveBinaryDocumentStream(asset.getDisplayName(), asset.getDescription(), stream,
asset.getJansModuleProperty());
log.info("Successfully stored asset - Path of saved new asset is :{}", path);
return asset;
}

private String copyAssetOnServer(Document asset, InputStream stream) {
log.info("Copy asset on server - asset:{}, stream:{}", asset, stream);
String result = null;
Expand All @@ -343,14 +335,10 @@ private String copyAssetOnServer(Document asset, InputStream stream) {
}

String filePath = path + File.separator + fileName;
log.info("documentStoreService:{}, filePath:{}, localDocumentStoreService:{} ", documentStoreService, filePath,
localDocumentStoreService);
log.info("documentStoreService:{}, filePath:{}", documentStoreService, filePath);
result = documentStoreService.saveDocumentStream(filePath, null, stream, List.of(documentStoreModuleName));
log.info("Asset saving result:{}", result);

InputStream newFile = documentStoreService.readDocumentAsStream(filePath);
log.info("Reading asset file newFile:{}", newFile);

return result;

}
Expand Down