Skip to content

Commit

Permalink
#8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pethers committed Mar 3, 2018
1 parent d52cf11 commit 9ab4ac4
Show file tree
Hide file tree
Showing 19 changed files with 232 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.hack23.cia.web.impl.ui.application.views.user.parliament.pagemode;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -35,6 +34,7 @@
import com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest;
import com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse;
import com.hack23.cia.service.api.action.kpi.ResourceType;
import com.hack23.cia.service.api.action.kpi.RuleViolation;
import com.hack23.cia.service.api.action.kpi.Status;
import com.hack23.cia.web.impl.ui.application.action.ViewAction;
import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
Expand Down Expand Up @@ -83,13 +83,13 @@ public Layout createContent(final String parameters, final MenuBar menuBar, fina

HorizontalLayout horizontalLayout = new HorizontalLayout();

for (Entry<Status, List<ComplianceCheck>> statusEntry : serviceResponse.getStatusMap().entrySet()) {
for (Entry<Status, List<RuleViolation>> statusEntry : serviceResponse.getStatusMap().entrySet()) {
horizontalLayout.addComponent(new CounterStatisticsCard(
VaadinIcons.WARNING,new CounterStatisticModel("ALL:" +statusEntry.getKey().toString(),statusEntry.getValue().size()).withShow(StatisticShow.Sum)
.withIconHidden().withShowOnlyStatistic(true),"ALL:" +statusEntry.getKey().toString()));
}

for (Entry<ResourceType, List<ComplianceCheck>> statusEntry : serviceResponse.getResourceTypeMap().entrySet()) {
for (Entry<ResourceType, List<RuleViolation>> statusEntry : serviceResponse.getResourceTypeMap().entrySet()) {
horizontalLayout.addComponent(new CounterStatisticsCard(
VaadinIcons.WARNING,new CounterStatisticModel("ALL:" +statusEntry.getKey().toString(),statusEntry.getValue().size()).withShow(StatisticShow.Sum)
.withIconHidden().withShowOnlyStatistic(true),"ALL:" +statusEntry.getKey().toString()));
Expand All @@ -99,7 +99,7 @@ VaadinIcons.WARNING,new CounterStatisticModel("ALL:" +statusEntry.getKey().toStr
panelContent.addComponent(horizontalLayout);

getGridFactory().createBasicBeanItemGrid(panelContent, ComplianceCheck.class, serviceResponse.getList(), "Risk",
new String[] { "name", "status", "resourceType", "ruleName" }, new String[] { "id", "ruleDescription" }, null, null, null);
new String[] { "name", "resourceType", "numberRuleViolations", "ruleSummary" }, new String[] { "id", "ruleViolations" }, null, null, null);

getPageActionEventHelper().createPageEvent(ViewAction.VISIT_PARLIAMENT_RANKING_VIEW, ApplicationEventGroup.USER,
NAME, parameters, pageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.NO_FIELD_NAMES_STYLE);
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final boolean equals(Object obj) {

@Override
public final String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.NO_FIELD_NAMES_STYLE);
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,34 @@
*/
public interface ComplianceCheck extends Serializable {


/**
* Gets the rule name.
*
* @return the rule name
*/
String getRuleName();

/**
* Gets the rule description.
* Gets the resource type.
*
* @return the rule description
* @return the resource type
*/
String getRuleDescription();
ResourceType getResourceType();

/**
* Gets the status.
* Gets the rule violations.
*
* @return the status
* @return the rule violations
*/
Status getStatus();
List<RuleViolation> getRuleViolations();

/**
* Gets the resource type.
* Gets the number rule violations.
*
* @return the resource type
* @return the number rule violations
*/
ResourceType getResourceType();
int getNumberRuleViolations();

/**
* Gets the rule violations.
* Gets the rule summary.
*
* @return the rule violations
* @return the rule summary
*/
List<RuleViolation> getRuleViolations();
String getRuleSummary();

/**
* Gets the id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public final class ComplianceCheckResponse extends AbstractResponse {
private List<ComplianceCheck> list;

/** The status map. */
private Map<Status,List<ComplianceCheck>> statusMap;
private Map<Status,List<RuleViolation>> statusMap;

/** The resource type map. */
private Map<ResourceType,List<ComplianceCheck>> resourceTypeMap;
private Map<ResourceType,List<RuleViolation>> resourceTypeMap;

/**
* Instantiates a new compliance check response.
Expand Down Expand Up @@ -76,17 +76,17 @@ public void setList(final List<ComplianceCheck> list) {
*
* @return the status map
*/
public Map<Status, List<ComplianceCheck>> getStatusMap() {
public Map<Status, List<RuleViolation>> getStatusMap() {
return statusMap;
}

/**
* Sets the status map.
*
* @param statusMap
* the status map
* the new status map
*/
public void setStatusMap(final Map<Status, List<ComplianceCheck>> statusMap) {
public void setStatusMap(final Map<Status, List<RuleViolation>> statusMap) {
this.statusMap = statusMap;
}

Expand All @@ -95,17 +95,17 @@ public void setStatusMap(final Map<Status, List<ComplianceCheck>> statusMap) {
*
* @return the resource type map
*/
public Map<ResourceType, List<ComplianceCheck>> getResourceTypeMap() {
public Map<ResourceType, List<RuleViolation>> getResourceTypeMap() {
return resourceTypeMap;
}

/**
* Sets the resource type map.
*
* @param resourceTypeMap
* the resource type map
* the new resource type map
*/
public void setResourceTypeMap(final Map<ResourceType, List<ComplianceCheck>> resourceTypeMap) {
public void setResourceTypeMap(final Map<ResourceType, List<RuleViolation>> resourceTypeMap) {
this.resourceTypeMap = resourceTypeMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,25 @@
*/
package com.hack23.cia.service.api.action.kpi;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
* The Class RuleViolation.
*/
public final class RuleViolation {

/** The id. */
private final String id;

/** The name. */
private final String name;

/** The resource type. */
private final ResourceType resourceType;

/** The rule name. */
private String ruleName;

Expand All @@ -38,6 +52,12 @@ public final class RuleViolation {
/**
* Instantiates a new rule violation.
*
* @param id
* the id
* @param name
* the name
* @param resourceType
* the resource type
* @param ruleName
* the rule name
* @param ruleDescription
Expand All @@ -47,14 +67,35 @@ public final class RuleViolation {
* @param status
* the status
*/
public RuleViolation(final String ruleName, final String ruleDescription, final String ruleGroup, final Status status) {
public RuleViolation(final String id,final String name,final ResourceType resourceType,final String ruleName, final String ruleDescription, final String ruleGroup, final Status status) {
super();
this.id = id;
this.name = name;
this.resourceType = resourceType;
this.ruleName = ruleName;
this.ruleDescription = ruleDescription;
this.ruleGroup = ruleGroup;
this.status = status;
}

/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}

/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}

/**
* Gets the rule name.
*
Expand Down Expand Up @@ -91,5 +132,37 @@ public Status getStatus() {
return status;
}

/**
* Gets the resource type.
*
* @return the resource type
*/
public ResourceType getResourceType() {
return resourceType;
}

/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public final boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public final String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}

/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public final int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.hack23.cia.service.impl.action.kpi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
Expand All @@ -40,6 +41,7 @@
import com.hack23.cia.service.api.action.kpi.ComplianceCheck;
import com.hack23.cia.service.api.action.kpi.ComplianceCheckRequest;
import com.hack23.cia.service.api.action.kpi.ComplianceCheckResponse;
import com.hack23.cia.service.api.action.kpi.RuleViolation;
import com.hack23.cia.service.impl.action.common.AbstractBusinessServiceImpl;
import com.hack23.cia.service.impl.action.common.BusinessService;
import com.hack23.cia.service.impl.rules.RulesEngine;
Expand Down Expand Up @@ -92,24 +94,24 @@ public ComplianceCheckResponse processService(
}

final ComplianceCheckResponse response = new ComplianceCheckResponse(ServiceResult.SUCCESS);
List<ComplianceCheck> list = rulesEngine.checkRulesCompliance();
List<ComplianceCheck> complianceList = rulesEngine.checkRulesCompliance();

Collections.sort(list, new Comparator<ComplianceCheck>() {
List<RuleViolation> ruleViolations = new ArrayList<RuleViolation>();

for (ComplianceCheck check : complianceList) {
ruleViolations.addAll(check.getRuleViolations());
}

Collections.sort(complianceList, new Comparator<ComplianceCheck>() {
@Override
public int compare(ComplianceCheck o1, ComplianceCheck o2) {
int status = o2.getStatus().compareTo(o1.getStatus());
if (status == 0) {
return o2.getRuleName().compareTo(o1.getRuleName());
} else {
return status;
}

return Integer.compare(o2.getRuleViolations().size(), o1.getRuleViolations().size());
}
});

response.setList(list);
response.setStatusMap(list.stream().collect(Collectors.groupingBy(ComplianceCheck::getStatus)));
response.setResourceTypeMap(list.stream().collect(Collectors.groupingBy(ComplianceCheck::getResourceType)));
response.setList(complianceList);
response.setStatusMap(ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getStatus)));
response.setResourceTypeMap(ruleViolations.stream().collect(Collectors.groupingBy(RuleViolation::getResourceType)));

eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
Expand Down
Loading

0 comments on commit 9ab4ac4

Please sign in to comment.