Skip to content

Commit

Permalink
[SYNCOPE-1768] Reviewing XMLContentExporter to work with tableThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Jun 28, 2023
1 parent 7bbc7bc commit b6482a7
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.syncope.client.console.widgets.ExtAlertWidget;
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.client.ui.commons.HttpResourceStream;
import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
import org.apache.syncope.client.ui.commons.annotations.ExtPage;
import org.apache.syncope.client.ui.commons.pages.BaseWebPage;
import org.apache.syncope.client.ui.commons.rest.ResponseHolder;
Expand All @@ -62,10 +63,12 @@
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
import org.apache.wicket.request.mapper.parameter.PageParameters;
Expand Down Expand Up @@ -118,15 +121,27 @@ public BasePage(final PageParameters parameters) {
body.add(new Label("os", systemInfo.getOs()));
body.add(new Label("jvm", systemInfo.getJvm()));

Model<Integer> tableThresholdModel = Model.of(100);
body.add(new TextField<>("tableThreshold", tableThresholdModel).add(
new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

private static final long serialVersionUID = -1107858522700306810L;

@Override
protected void onUpdate(final AjaxRequestTarget target) {
// nothing to do
}
}));

Link<Void> dbExportLink = new Link<>("dbExportLink") {

private static final long serialVersionUID = -4331619903296515985L;

@Override
public void onClick() {
try {
HttpResourceStream stream = new HttpResourceStream(
new ResponseHolder(syncopeRestClient.exportInternalStorageContent()));
HttpResourceStream stream = new HttpResourceStream(new ResponseHolder(
syncopeRestClient.exportInternalStorageContent(tableThresholdModel.getObject())));

ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream);
rsrh.setFileName(stream.getFilename() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class SyncopeRestClient extends BaseRestClient {

private static final long serialVersionUID = -9013241672773442286L;

public Response exportInternalStorageContent() {
return getService(SyncopeService.class).exportInternalStorageContent();
public Response exportInternalStorageContent(final int tableThreshold) {
return getService(SyncopeService.class).exportInternalStorageContent(tableThreshold);
}

public List<GroupTO> searchAssignableGroups(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ <h5><wicket:message key="exportConfiguration"/></h5>
<span class="info-box-icon"><i class="fa fa-download"></i></span>

<div class="info-box-content">
<span class="info-box-text"><a wicket:id="dbExportLink"><wicket:message key="download"/></a></span>
<span class="info-box-text">
<label><wicket:message key="tableThreshold"/></label>
<input type="text" class="form-control" wicket:id="tableThreshold"/>
<a wicket:id="dbExportLink"><wicket:message key="download"/></a>
</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ highContrast=Toggle high contrast mode
fontSize=Change font size
delegations=Delegations
endDelegation=End Delegation
tableThreshold=Table Threshold
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ highContrast=(Dis)attiva alto contrasto
fontSize=Dimensione carattere
delegations=Deleghe
endDelegation=Termina Delega
tableThreshold=Limite righe tabella
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ highContrast=Toggle high contrast mode
fontSize=Change font size
delegations=Delegations
endDelegation=End Delegation
tableThreshold=Table Threshold
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ highContrast=Toggle high contrast mode
fontSize=Change font size
delegations=Delegations
endDelegation=End Delegation
tableThreshold=Table Threshold
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ highContrast=Toggle high contrast mode
fontSize=Change font size
delegations=Delegations
endDelegation=End Delegation
tableThreshold=Table Threshold
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ PagedResult<GroupTO> searchAssignableGroups(
/**
* Exports internal storage content as downloadable XML file.
*
* @param tableThreshold the maximum number of rows to take for each table of internal storage
* @return internal storage content as downloadable XML file
*/
@GET
@Path("internalStorage/stream")
Response exportInternalStorageContent();
Response exportInternalStorageContent(@QueryParam("tableThreshold") @DefaultValue("100") int tableThreshold);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@
import org.apache.syncope.core.provisioning.api.rules.RuleEnforcer;
import org.apache.syncope.core.provisioning.java.utils.TemplateUtils;
import org.apache.syncope.core.spring.security.SecurityProperties;
import org.apache.syncope.core.workflow.api.AnyObjectWorkflowAdapter;
import org.apache.syncope.core.workflow.api.GroupWorkflowAdapter;
import org.apache.syncope.core.workflow.api.UserWorkflowAdapter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -483,16 +480,13 @@ public SecurityQuestionLogic securityQuestionLogic(
@ConditionalOnMissingBean
@Bean
public SyncopeLogic syncopeLogic(
final ContentExporter exporter,
final UserWorkflowAdapter uwfAdapter,
final RealmDAO realmDAO,
final AnyTypeDAO anyTypeDAO,
final GroupDAO groupDAO,
final ConfParamOps confParamOps,
final GroupDataBinder groupDataBinder,
final AnySearchDAO anySearchDAO,
final GroupWorkflowAdapter gwfAdapter,
final AnyObjectWorkflowAdapter awfAdapter) {
final GroupDataBinder groupDataBinder,
final ConfParamOps confParamOps,
final ContentExporter exporter) {

return new SyncopeLogic(
realmDAO,
Expand All @@ -501,10 +495,7 @@ public SyncopeLogic syncopeLogic(
anySearchDAO,
groupDataBinder,
confParamOps,
exporter,
uwfAdapter,
gwfAdapter,
awfAdapter);
exporter);
}

@ConditionalOnMissingBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
import org.apache.syncope.core.persistence.api.entity.group.TypeExtension;
import org.apache.syncope.core.provisioning.api.data.GroupDataBinder;
import org.apache.syncope.core.spring.security.AuthContextUtils;
import org.apache.syncope.core.workflow.api.AnyObjectWorkflowAdapter;
import org.apache.syncope.core.workflow.api.GroupWorkflowAdapter;
import org.apache.syncope.core.workflow.api.UserWorkflowAdapter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -62,42 +59,30 @@ public class SyncopeLogic extends AbstractLogic<EntityTO> {

protected final GroupDAO groupDAO;

protected final AnySearchDAO searchDAO;
protected final AnySearchDAO anySearchDAO;

protected final GroupDataBinder groupDataBinder;

protected final ConfParamOps confParamOps;

protected final ContentExporter exporter;

protected final UserWorkflowAdapter uwfAdapter;

protected final GroupWorkflowAdapter gwfAdapter;

protected final AnyObjectWorkflowAdapter awfAdapter;

public SyncopeLogic(
final RealmDAO realmDAO,
final AnyTypeDAO anyTypeDAO,
final GroupDAO groupDAO,
final AnySearchDAO searchDAO,
final AnySearchDAO anySearchDAO,
final GroupDataBinder groupDataBinder,
final ConfParamOps confParamOps,
final ContentExporter exporter,
final UserWorkflowAdapter uwfAdapter,
final GroupWorkflowAdapter gwfAdapter,
final AnyObjectWorkflowAdapter awfAdapter) {
final ContentExporter exporter) {

this.realmDAO = realmDAO;
this.anyTypeDAO = anyTypeDAO;
this.groupDAO = groupDAO;
this.searchDAO = searchDAO;
this.anySearchDAO = anySearchDAO;
this.groupDataBinder = groupDataBinder;
this.confParamOps = confParamOps;
this.exporter = exporter;
this.uwfAdapter = uwfAdapter;
this.gwfAdapter = gwfAdapter;
this.awfAdapter = awfAdapter;
}

public boolean isSelfRegAllowed() {
Expand Down Expand Up @@ -133,12 +118,12 @@ public Pair<Integer, List<GroupTO>> searchAssignableGroups(
}
SearchCond searchCond = SearchCond.getLeaf(termCond);

int count = searchDAO.count(base, true, SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);
int count = anySearchDAO.count(base, true, SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);

OrderByClause orderByClause = new OrderByClause();
orderByClause.setField("name");
orderByClause.setDirection(OrderByClause.Direction.ASC);
List<Group> matching = searchDAO.search(
List<Group> matching = anySearchDAO.search(
base,
true,
SyncopeConstants.FULL_ADMIN_REALMS,
Expand Down Expand Up @@ -169,14 +154,12 @@ public TypeExtensionTO readTypeExtension(final String groupName) {

@PreAuthorize("hasRole('" + IdRepoEntitlement.KEYMASTER + "')")
@Transactional(readOnly = true)
public void exportInternalStorageContent(final OutputStream os) {
public void exportInternalStorageContent(final int tableThreshold, final OutputStream os) {
try {
exporter.export(
AuthContextUtils.getDomain(),
os,
uwfAdapter.getPrefix(),
gwfAdapter.getPrefix(),
awfAdapter.getPrefix());
tableThreshold,
os);
LOG.debug("Internal storage content successfully exported");
} catch (Exception e) {
LOG.error("While exporting internal storage content", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public Response batch() {
}

@Override
public Response exportInternalStorageContent() {
StreamingOutput sout = (os) -> logic.exportInternalStorageContent(os);
public Response exportInternalStorageContent(final int tableThreshold) {
StreamingOutput sout = os -> logic.exportInternalStorageContent(tableThreshold, os);

return Response.ok(sout).
type(MediaType.TEXT_XML).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public interface ContentExporter extends ContentDealer {

void export(
String domain,
OutputStream output,
String uwfPrefix,
String gwfPrefix,
String awfPrefix)
int tableThreshold,
OutputStream output)
throws SAXException, TransformerConfigurationException;
}
Loading

0 comments on commit b6482a7

Please sign in to comment.