Skip to content

Commit

Permalink
Fix more checkstyle warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussemNasri committed Sep 1, 2023
1 parent 991e590 commit 136d710
Show file tree
Hide file tree
Showing 33 changed files with 237 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ public List<CVEAuditServer> listSystemsByPatchStatus(User loggedInUser,
}
}

List<CVEAuditServer> result = CVEAuditManagerOVAL.listSystemsByPatchStatus(
loggedInUser, cveIdentifier, patchStatuses);
try {
List<CVEAuditServer> result = CVEAuditManagerOVAL.listSystemsByPatchStatus(
loggedInUser, cveIdentifier, patchStatuses);

result.sort(Comparator.comparingInt(s -> s.getPatchStatus().getRank()));
result.sort(Comparator.comparingInt(s -> s.getPatchStatus().getRank()));

return result;
return result;
}
catch (UnknownCVEIdentifierException e) {
throw new UnknownCVEIdentifierFaultException();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,28 @@
*
*/
public class CVEAuditManagerOVAL {
private static Logger LOG = LogManager.getLogger(CVEAuditManagerOVAL.class);

private static final Logger LOG = LogManager.getLogger(CVEAuditManagerOVAL.class);

private CVEAuditManagerOVAL() {

}

/**
* List visible systems with their patch status regarding a given CVE identifier.
*
* */
* @param user the calling user
* @param cveIdentifier the CVE identifier to lookup
* @param patchStatuses the patch statuses
* @return list of system records with patch status
* @throws UnknownCVEIdentifierException if the CVE number is not known
*/
public static List<CVEAuditServer> listSystemsByPatchStatus(User user, String cveIdentifier,
EnumSet<PatchStatus> patchStatuses) {
EnumSet<PatchStatus> patchStatuses)
throws UnknownCVEIdentifierException {
if (CVEAuditManager.isCVEIdentifierUnknown(cveIdentifier)) {
throw new UnknownCVEIdentifierException();
}

List<CVEAuditServer> result = new ArrayList<>();

Expand All @@ -75,7 +90,8 @@ public static List<CVEAuditServer> listSystemsByPatchStatus(User user, String cv
CVEAuditManager.doAuditSystem(clientServer.getId(), resultsBySystem.get(clientServer.getId()));

if (doesSupportOVALAuditing(clientServer)) {
systemAuditResult = doAuditSystem(cveIdentifier, resultsBySystem.get(clientServer.getId()), clientServer);
systemAuditResult = doAuditSystem(cveIdentifier, resultsBySystem.get(clientServer.getId()),
clientServer);
systemAuditResult.setChannels(auditWithChannelsResult.getChannels());
systemAuditResult.setErratas(auditWithChannelsResult.getErratas());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,13 @@ public void testFindAllTargetProducts() throws Exception {
public void testSetPatchStatus() {
assertEquals(PatchStatus.PATCHED, CVEAuditManager.getPatchStatus(true, true, true, false));
assertEquals(PatchStatus.PATCHED, CVEAuditManager.getPatchStatus(true, false, true, false));
assertEquals(PatchStatus.AFFECTED_FULL_PATCH_APPLICABLE, CVEAuditManager.getPatchStatus(false, true, true, false));
assertEquals(PatchStatus.AFFECTED_FULL_PATCH_APPLICABLE,
CVEAuditManager.getPatchStatus(false, true, true, false));
assertEquals(PatchStatus.AFFECTED_PATCH_INAPPLICABLE,
CVEAuditManager.getPatchStatus(false, false, true, false));
assertEquals(PatchStatus.NOT_AFFECTED, CVEAuditManager.getPatchStatus(false, false, false, false));
assertEquals(PatchStatus.AFFECTED_FULL_PATCH_APPLICABLE, CVEAuditManager.getPatchStatus(false, true, true, true));
assertEquals(PatchStatus.AFFECTED_FULL_PATCH_APPLICABLE,
CVEAuditManager.getPatchStatus(false, true, true, true));
assertEquals(PatchStatus.AFFECTED_PATCH_INAPPLICABLE_SUCCESSOR_PRODUCT,
CVEAuditManager.getPatchStatus(false, false, true, true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import spark.ModelAndView;
import spark.Request;
import spark.Response;
Expand Down
12 changes: 0 additions & 12 deletions java/code/src/com/suse/oval/OsFamily.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,4 @@ public enum OsFamily {
OsFamily(String fullnameIn, String vendorIn) {
this(fullnameIn, fullnameIn.toLowerCase(), vendorIn);
}

public String fullname() {
return fullname;
}

public String shortname() {
return shortname;
}

public String vendor() {
return vendor;
}
}
8 changes: 4 additions & 4 deletions java/code/src/com/suse/oval/ShallowSystemPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
public void setName(String nameIn) {
this.name = nameIn;
}

public String getEvr() {
return evr;
}

public void setEvr(String evr) {
this.evr = evr;
public void setEvr(String evrIn) {
this.evr = evrIn;
}

/**
Expand Down
30 changes: 30 additions & 0 deletions java/code/src/com/suse/oval/cpe/Cpe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public Cpe() {
update = "";
}

/**
* Gets the vendor value or empty if not set
*
* @return the vendor value or an empty string if not set
* */
public String getVendor() {
return vendor;
}
Expand All @@ -47,6 +52,11 @@ void setVendor(String vendorIn) {
}
}

/**
* Gets the product value or empty if not set
*
* @return the product value or an empty string if not set
* */
public String getProduct() {
return product;
}
Expand All @@ -57,6 +67,11 @@ void setProduct(String productIn) {
}
}

/**
* Gets the version value or empty if not set
*
* @return the version value or an empty string if not set
* */
public String getVersion() {
return version;
}
Expand All @@ -67,6 +82,11 @@ void setVersion(String versionIn) {
}
}

/**
* Gets the update value or empty if not set
*
* @return the update value or an empty string if not set
* */
public String getUpdate() {
return update;
}
Expand All @@ -77,10 +97,20 @@ void setUpdate(String updateIn) {
}
}

/**
* Parse the given Cpe URI string and returns a {@link Cpe} object
*
* @return a cpe object with all the Cpe information
* */
public static Cpe parse(String cpe) {
return CPE_PARSER.parse(cpe);
}

/**
* Converts and returns the Cpe as plain text URI
*
* @return the cpe as URI
* */
public String asString() {
String cpe = "cpe:/o:" + vendor + ":" + product + ":" + version + ":" + update;

Expand Down
29 changes: 29 additions & 0 deletions java/code/src/com/suse/oval/cpe/CpeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,55 @@
public final class CpeBuilder {
private final Cpe cpe = new Cpe();

/**
* Sets the vendor and returns {@code CpeBuilder} to continue building the {@link Cpe} object
*
* @param vendor the vendor to set
* @return the CpeBuilder to continue building the Cpe object
* */
public CpeBuilder withVendor(String vendor) {
cpe.setVendor(vendor);
return this;
}

/**
* Sets the product and returns {@code CpeBuilder} to continue building the {@link Cpe} object
*
* @param product the product to set
* @return the CpeBuilder to continue building the Cpe object
* */
public CpeBuilder withProduct(String product) {
cpe.setProduct(product);
return this;
}

/**
* Sets the version and returns {@code CpeBuilder} to continue building the {@link Cpe} object
*
* @param version the version to set
* @return the CpeBuilder to continue building the Cpe object
* */
public CpeBuilder withVersion(String version) {
cpe.setVersion(version);
return this;
}

/**
* Sets the update and returns {@code CpeBuilder} to continue building the {@link Cpe} object
*
* @param update the update value to set
* @return the CpeBuilder to continue building the Cpe object
* */
public CpeBuilder withUpdate(String update) {
cpe.setUpdate(update);
return this;
}

/**
* Builds the {@link Cpe} object
*
* @return the built cpe
* */
public Cpe build() {
return cpe;
}
Expand Down
2 changes: 1 addition & 1 deletion java/code/src/com/suse/oval/cpe/SimpleCpeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SimpleCpeParser {
* CPE: <b>cpe:/o:opensuse:leap:15.4</b>
* <br>
* PART: <b>o</b> <i>(it's an operating system's CPE)</i><br>
* VENDOR: <b>opensuse</b> <i>(CPE describes a product manufactured by openSUSE)<i/><br>
* VENDOR: <b>opensuse</b> <i>(CPE describes a product manufactured by openSUSE)</i><br>
* PRODUCT: <b>leap</b> <i>(The product name is leap)</i><br>
* VERSION: <b>15.4</b> <i>(The product version is 15.4)</i><br>
* <br><br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.suse.oval.db;

import com.redhat.rhn.domain.errata.Cve;

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

Expand Down
25 changes: 25 additions & 0 deletions java/code/src/com/suse/oval/exceptions/OvalParserException.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,44 @@

package com.suse.oval.exceptions;

/**
* A runtime exception throne by {@link com.suse.oval.OvalParser} when it encounters errors while parsing an OVAL file
* */
public class OvalParserException extends RuntimeException {

/**
* Constructs a new parser exception with null as its detail message. The cause is not initialized, and may
* subsequently be initialized by a call to initCause.
* */
public OvalParserException() {
super();
}

/**
* Constructs a new parser exception with the specified detail message.
*
* @param message the detail message. The detail message is saved for later retrieval by the getMessage() method.
* */

public OvalParserException(String message) {
super(message);
}

/**
* Constructs a new parser exception with the specified cause.
*
* @param cause the cause (which is saved for later retrieval by the getCause() method).
* */
public OvalParserException(Throwable cause) {
super(cause);
}

/**
* Constructs a new parser exception with the specified detail message and cause.
*
* @param cause the cause (which is saved for later retrieval by the getCause() method).
* @param message the detail message. The detail message is saved for later retrieval by the getMessage() method.
* */
public OvalParserException(String message, Throwable cause) {
super(message, cause);
}
Expand Down
9 changes: 4 additions & 5 deletions java/code/src/com/suse/oval/manager/OvalObjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public OvalObjectManager(List<ObjectType> objects) {

/**
* Looks up an OVAL object with an id of {@code objectId}
*
* @param objectId the object id to look up
* @return the cached {@link ObjectType} object that correspond to the object id
* */
public ObjectType get(String objectId) {
ObjectType object = objectsMap.get(objectId);
Expand All @@ -46,11 +49,7 @@ public ObjectType get(String objectId) {
/**
* Check if an OVAL object with an id of {@code objectId} exists
* */
public boolean exists(String objectId) {
protected boolean exists(String objectId) {
return objectsMap.containsKey(objectId);
}

public void add(ObjectType objectType) {
objectsMap.put(objectType.getId(), objectType);
}
}
4 changes: 2 additions & 2 deletions java/code/src/com/suse/oval/ovaltypes/AdvisoryCveType.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String getCve() {
return cve;
}

public void setCve(String cve) {
this.cve = cve;
public void setCve(String cveIn) {
this.cve = cveIn;
}
}
Loading

0 comments on commit 136d710

Please sign in to comment.