Skip to content

Commit

Permalink
Fix #340
Browse files Browse the repository at this point in the history
  • Loading branch information
hmiguim committed Jan 3, 2023
1 parent 8dc7b59 commit ab2229b
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
import static com.databasepreservation.common.client.ViewerConstants.SOLR_INDEX_ROW_COLLECTION_NAME_PREFIX;
import static com.databasepreservation.common.client.ViewerConstants.SOLR_SEARCHES_DATABASE_UUID;

import com.databasepreservation.common.client.models.structure.ViewerLobStoreType;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -87,6 +84,7 @@
import com.databasepreservation.common.client.models.status.denormalization.DenormalizeConfiguration;
import com.databasepreservation.common.client.models.structure.ViewerDatabase;
import com.databasepreservation.common.client.models.structure.ViewerDatabaseStatus;
import com.databasepreservation.common.client.models.structure.ViewerLobStoreType;
import com.databasepreservation.common.client.models.structure.ViewerRow;
import com.databasepreservation.common.client.models.structure.ViewerTable;
import com.databasepreservation.common.client.models.structure.ViewerType;
Expand Down Expand Up @@ -560,7 +558,7 @@ private Response handleClobDownload(TableStatus tableConfiguration, ViewerRow ro
}

private Response handleExternalLobDownload(TableStatus tableConfiguration, ViewerRow row, int columnIndex)
throws IOException {
throws IOException {
final String lobLocation = row.getCells().get(tableConfiguration.getColumnByIndex(columnIndex).getId()).getValue();
final java.nio.file.Path lobPath = Paths.get(lobLocation);
final java.nio.file.Path completeLobPath = ViewerFactory.getViewerConfiguration().getSIARDFilesPath()
Expand Down Expand Up @@ -612,9 +610,9 @@ private Response handleInternalLobDownload(String databasePath, TableStatus tabl
throw new GenericException("Zip archive entry is missing");
}

return ApiUtils.okResponse(new StreamResponse(handlebarsFilename, handlebarsMimeType,
DownloadUtils.stream(new BufferedInputStream(zipFile.getInputStream(entry)))));
}
return ApiUtils.okResponse(new StreamResponse(handlebarsFilename, handlebarsMimeType,
DownloadUtils.stream(new BufferedInputStream(zipFile.getInputStream(entry)))));
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.springframework.stereotype.Service;

import com.databasepreservation.common.client.ViewerConstants;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroups;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroup;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroupsList;
import com.databasepreservation.common.client.services.ContextService;
import com.databasepreservation.common.server.ServerTools;
Expand Down Expand Up @@ -64,7 +64,7 @@ public Map<String, List<String>> getSharedProperties(String localeString) {
}

@Override
public Set<AuthorizationGroups> getAuthorizationGroupsList() {
public Set<AuthorizationGroup> getAuthorizationGroupsList() {
ControllerAssistant controllerAssistant = new ControllerAssistant() {};
controllerAssistant.checkRoles(request);
AuthorizationGroupsList authorizationGroupsList = ViewerConfiguration.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.databasepreservation.common.client.index.FindRequest;
import com.databasepreservation.common.client.index.IndexResult;
import com.databasepreservation.common.client.index.filter.AndFiltersParameters;
import com.databasepreservation.common.client.index.filter.EmptyKeyFilterParameter;
import com.databasepreservation.common.client.index.filter.Filter;
import com.databasepreservation.common.client.index.filter.FilterParameter;
import com.databasepreservation.common.client.index.filter.OrFiltersParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.databasepreservation.common.client.common.visualization.manager.SIARDPanel.navigation.SIARDNavigationPanel;
import com.databasepreservation.common.client.common.visualization.manager.SIARDPanel.navigation.ValidationNavigationPanel;
import com.databasepreservation.common.client.index.IsIndexed;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroups;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroup;
import com.databasepreservation.common.client.models.structure.ViewerDatabase;
import com.databasepreservation.common.client.models.structure.ViewerDatabaseStatus;
import com.databasepreservation.common.client.services.ContextService;
Expand Down Expand Up @@ -142,7 +142,7 @@ private void populateNavigationPanels() {

if (ApplicationType.getType().equals(ViewerConstants.APPLICATION_ENV_SERVER)) {
DatabaseService.Util.call((Set<String> databasePermissions) -> {
ContextService.Util.call((Set<AuthorizationGroups> authorizationGroups) -> {
ContextService.Util.call((Set<AuthorizationGroup> authorizationGroups) -> {
permissionsNavigationPanel = PermissionsNavigationPanel.getInstance(database, databasePermissions, authorizationGroups);
if (permissionsNavigationPanel.hasPermissionsOrGroups()) {
navigationPanels.add(permissionsNavigationPanel.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.databasepreservation.common.client.common.utils.CommonClientUtils;
import com.databasepreservation.common.client.common.utils.html.LabelUtils;
import com.databasepreservation.common.client.common.visualization.manager.SIARDPanel.SIARDManagerPage;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroups;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroup;
import com.databasepreservation.common.client.models.structure.ViewerDatabase;
import com.databasepreservation.common.client.services.DatabaseService;
import com.databasepreservation.common.client.widgets.Alert;
Expand All @@ -37,7 +37,6 @@
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlowPanel;

import com.google.gwt.user.client.ui.Widget;
import config.i18n.client.ClientMessages;

/**
Expand All @@ -50,7 +49,7 @@ public class PermissionsNavigationPanel {

private ViewerDatabase database;
private Set<String> databasePermissions;
private Set<AuthorizationGroups> groups;
private Set<AuthorizationGroup> groups;
private boolean hasPermissionsOrGroups = true;
private FlowPanel body;
private FlowPanel bottom;
Expand All @@ -59,13 +58,13 @@ public class PermissionsNavigationPanel {
private boolean overrideMissingGroups = false;

public static PermissionsNavigationPanel getInstance(ViewerDatabase database, Set<String> databasePermissions,
Set<AuthorizationGroups> authorizationGroups) {
Set<AuthorizationGroup> authorizationGroups) {
return instances.computeIfAbsent(database.getUuid(),
k -> new PermissionsNavigationPanel(database, databasePermissions, authorizationGroups));
}

public PermissionsNavigationPanel(ViewerDatabase database, Set<String> databasePermissions,
Set<AuthorizationGroups> authorizationGroups) {
Set<AuthorizationGroup> authorizationGroups) {
this.database = database;
this.groups = authorizationGroups;
this.databasePermissions = databasePermissions;
Expand Down Expand Up @@ -104,9 +103,9 @@ private void updateBody() {
} else {
ArrayList<String> permissionOrGroupsList = new ArrayList<>();
// Add the corresponding label to the permission
for (AuthorizationGroups authorizationGroups : groups) {
if (databasePermissions.contains(authorizationGroups.getAttributeValue())) {
permissionOrGroupsList.add(authorizationGroups.getLabel());
for (AuthorizationGroup authorizationGroup : groups) {
if (databasePermissions.contains(authorizationGroup.getAttributeValue())) {
permissionOrGroupsList.add(authorizationGroup.getLabel());
}
}

Expand Down Expand Up @@ -166,10 +165,10 @@ private FlowPanel getGroupsTable() {
permissionListPanel
.add(new Alert(Alert.MessageAlertType.INFO, messages.SIARDHomePageDialogDetailsForPermissionsList()));

Column<AuthorizationGroups, Boolean> checkbox = new Column<AuthorizationGroups, Boolean>(
Column<AuthorizationGroup, Boolean> checkbox = new Column<AuthorizationGroup, Boolean>(
new CheckboxCell(true, true)) {
@Override
public Boolean getValue(AuthorizationGroups group) {
public Boolean getValue(AuthorizationGroup group) {
return databasePermissions.contains(group.getAttributeValue());
}
};
Expand All @@ -188,35 +187,35 @@ public Boolean getValue(AuthorizationGroups group) {
}
});

BasicTablePanel<AuthorizationGroups> cellTable = new BasicTablePanel<>(new FlowPanel(),
BasicTablePanel<AuthorizationGroup> cellTable = new BasicTablePanel<>(new FlowPanel(),
SafeHtmlUtils.EMPTY_SAFE_HTML, groups.iterator(),
new BasicTablePanel.ColumnInfo<AuthorizationGroups>("", 3, checkbox),
new BasicTablePanel.ColumnInfo<AuthorizationGroups>(messages.SIARDHomePageLabelForPermissionsTableGroupLabel(), 7,
new TooltipColumn<AuthorizationGroups>() {
new BasicTablePanel.ColumnInfo<AuthorizationGroup>("", 3, checkbox),
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(messages.SIARDHomePageLabelForPermissionsTableGroupLabel(), 7,
new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroups group) {
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getLabel());
}
}, "force_column_ellipsis"),
new BasicTablePanel.ColumnInfo<AuthorizationGroups>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeName(), 7, new TooltipColumn<AuthorizationGroups>() {
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeName(), 7, new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroups group) {
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getAttributeName());
}
}, "force_column_ellipsis"),
new BasicTablePanel.ColumnInfo<AuthorizationGroups>(
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeOperator(), 7,
new TooltipColumn<AuthorizationGroups>() {
new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroups group) {
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getAttributeOperator());
}
}, "force_column_ellipsis"),
new BasicTablePanel.ColumnInfo<AuthorizationGroups>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeValue(), 0, new TooltipColumn<AuthorizationGroups>() {
new BasicTablePanel.ColumnInfo<AuthorizationGroup>(
messages.SIARDHomePageLabelForPermissionsTableGroupAttributeValue(), 0, new TooltipColumn<AuthorizationGroup>() {
@Override
public SafeHtml getValue(AuthorizationGroups group) {
public SafeHtml getValue(AuthorizationGroup group) {
return SafeHtmlUtils.fromString(group.getAttributeValue());
}
}, "force_column_ellipsis"));
Expand Down Expand Up @@ -248,7 +247,7 @@ private Set<String> retrieveMissingGroups() {
Set<String> missingGroups = new HashSet<>();
for (String permission : databasePermissions) {
boolean foundGroup = false;
for (AuthorizationGroups group : groups) {
for (AuthorizationGroup group : groups) {
if (group.getAttributeValue().equals(permission)) {
foundGroup = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @author Gabriel Barros <[email protected]>
*/
public class AuthorizationGroups implements Serializable {
public class AuthorizationGroup implements Serializable {
public enum Type {
DEFAULT, CUSTOM
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonIgnore;

Expand All @@ -21,29 +19,24 @@
public class AuthorizationGroupsList implements Serializable {
private static final long serialVersionUID = -3730186735554294942L;

private Set<AuthorizationGroups> authorizationGroupsList = new HashSet<>();
private Set<AuthorizationGroup> authorizationGroupList = new HashSet<>();

public Set<AuthorizationGroups> getAuthorizationGroupsList() {
return authorizationGroupsList;
public Set<AuthorizationGroup> getAuthorizationGroupsList() {
return authorizationGroupList;
}

@JsonIgnore
public AuthorizationGroups get(String permission) {
for (AuthorizationGroups authorizationGroups : authorizationGroupsList) {
if (authorizationGroups.getAttributeValue().equals(permission)) {
return authorizationGroups;
public AuthorizationGroup get(String permission) {
for (AuthorizationGroup authorizationGroup : authorizationGroupList) {
if (authorizationGroup.getAttributeValue().equals(permission)) {
return authorizationGroup;
}
}
return null;
}

@JsonIgnore
public List<String> getAllAttributeNames() {
return authorizationGroupsList.stream().map(AuthorizationGroups::getAttributeName).collect(Collectors.toList());
}

@JsonIgnore
public void add(AuthorizationGroups authorizationGroups) {
this.authorizationGroupsList.add(authorizationGroups);
public void add(AuthorizationGroup authorizationGroup) {
this.authorizationGroupList.add(authorizationGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import com.databasepreservation.common.client.ViewerConstants;
import com.databasepreservation.common.client.common.DefaultMethodCallback;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroups;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroup;
import com.google.gwt.core.client.GWT;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -77,5 +77,5 @@ Map<String, List<String>> getSharedProperties(
@Path("/authorizations")
@Operation(summary = "Gets the authorizations group list")
@Produces(MediaType.APPLICATION_JSON)
Set<AuthorizationGroups> getAuthorizationGroupsList();
Set<AuthorizationGroup> getAuthorizationGroupsList();
}
Loading

0 comments on commit ab2229b

Please sign in to comment.