Skip to content

Commit

Permalink
MiscUtil: few more renames/resignature to clarify methods
Browse files Browse the repository at this point in the history
- unorderedArrayEquals 3rd param is now EqualsChecker, not Comparator
- asLong(XMLGregorianCalendar) renamed to asMillis
- binaryToHex/hexToBinary renamed from binary to bytes (meaning byte[])
- find renamed to findWithComparator + new find with EqualsChecker
  • Loading branch information
virgo47 committed Feb 9, 2023
1 parent 4d3be35 commit 3a96def
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5135,7 +5135,7 @@ public static CredentialsPolicyType getPasswordCredentialsPolicy(PrismObject<? e

@Contract("_,true->!null")
public static Long getTimestampAsLong(XMLGregorianCalendar cal, boolean currentIfNull) {
Long calAsLong = MiscUtil.asLong(cal);
Long calAsLong = MiscUtil.asMillis(cal);
if (calAsLong == null) {
if (currentIfNull) {
return System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ private <R extends AbstractRoleType> void addAssignmentOrInducement(R abstractRo

private static String getRoleOid(String name) {
String roleHexName = StringUtils.leftPad(
MiscUtil.binaryToHex(name.getBytes(StandardCharsets.UTF_8)), 24, "0");
MiscUtil.bytesToHex(name.getBytes(StandardCharsets.UTF_8)), 24, "0");
return "99999999-" + roleHexName.substring(0, 4) + '-' + roleHexName.substring(4, 8)
+ '-' + roleHexName.substring(8, 12) + '-' + roleHexName.substring(12, 24);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ public void test145ModifyAccountJackJpegPhoto() throws Exception {
OperationResult result = task.getResult();

byte[] bytesIn = Files.readAllBytes(Paths.get(ProvisioningTestUtil.DOT_JPG_FILENAME));
displayValue("Bytes in", MiscUtil.binaryToHex(bytesIn));
displayValue("Bytes in", MiscUtil.bytesToHex(bytesIn));

ItemName jpegPhotoQName = new ItemName(NS_RI, "jpegPhoto");
PropertyDelta<byte[]> jpegPhotoDelta =
Expand Down Expand Up @@ -1016,7 +1016,7 @@ public void test145ModifyAccountJackJpegPhoto() throws Exception {
PrismProperty<byte[]> jpegPhotoAttr = attributesContainer.findProperty(jpegPhotoQName);
byte[] bytesOut = jpegPhotoAttr.getValues().get(0).getValue();

displayValue("Bytes out", MiscUtil.binaryToHex(bytesOut));
displayValue("Bytes out", MiscUtil.bytesToHex(bytesOut));

assertEquals("Byte length changed (shadow)", bytesIn.length, bytesOut.length);
assertArrayEquals("Bytes do not match (shadow)", bytesIn, bytesOut);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/*
* Copyright (C) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sqale.audit.qmodel;

import static com.evolveum.midpoint.util.MiscUtil.binaryToHexPreview;

import java.time.Instant;
import java.util.UUID;

import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;
import com.evolveum.prism.xml.ns._public.types_3.ChangeTypeType;

Expand Down Expand Up @@ -52,10 +51,10 @@ public String toString() {
"recordId=" + recordId +
", timestamp=" + timestamp +
", checksum='" + checksum + '\'' +
", delta=" + binaryToHexPreview(delta) +
", delta=" + MiscUtil.bytesToHexPreview(delta) +
", deltaOid=" + deltaOid +
", deltaType=" + deltaType +
", fullResult=" + binaryToHexPreview(fullResult) +
", fullResult=" + MiscUtil.bytesToHexPreview(fullResult) +
", objectNameNorm='" + objectNameNorm + '\'' +
", objectNameOrig='" + objectNameOrig + '\'' +
", resourceOid=" + resourceOid +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*
* Copyright (C) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sql.audit.beans;

import static com.evolveum.midpoint.util.MiscUtil.binaryToHexPreview;

import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.repo.sql.audit.querymodel.QAuditDelta;
import com.evolveum.midpoint.util.MiscUtil;

/**
* Querydsl "row bean" type related to {@link QAuditDelta}.
Expand Down Expand Up @@ -47,10 +46,10 @@ public String toString() {
return "MAuditDelta{" +
"recordId=" + recordId +
", checksum='" + checksum + '\'' +
", delta=" + binaryToHexPreview(delta) +
", delta=" + MiscUtil.bytesToHexPreview(delta) +
", deltaOid='" + deltaOid + '\'' +
", deltaType=" + deltaType +
", fullResult=" + binaryToHexPreview(fullResult) +
", fullResult=" + MiscUtil.bytesToHexPreview(fullResult) +
", objectNameNorm='" + objectNameNorm + '\'' +
", objectNameOrig='" + objectNameOrig + '\'' +
", resourceNameNorm='" + resourceNameNorm + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static <T extends Comparable<T>> T convertTimestampToPathType(

long timestamp;
if (value instanceof XMLGregorianCalendar) {
timestamp = MiscUtil.asLong((XMLGregorianCalendar) value);
timestamp = MiscUtil.asMillis((XMLGregorianCalendar) value);
} else {
throw new IllegalArgumentException(
"Unsupported temporal type " + value.getClass() + " for value: " + value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected String valueToString(Object o) {
} else if (o instanceof Null) {
return "NULL";
} else if (o.getClass() == byte[].class) {
return MiscUtil.binaryToHexPreview((byte[]) o, BYTE_ARRAY_PREVIEW_LEN);
return MiscUtil.bytesToHexPreview((byte[]) o, BYTE_ARRAY_PREVIEW_LEN);
} else if (o.getClass().isArray()) {
return ArrayUtils.toString(o);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private boolean isStartingForTooLong(NodeType node) {
}

private boolean isCheckInTimeLagging(NodeType node, int secondsLimit) {
Long lastCheckInTimestamp = MiscUtil.asLong(node.getLastCheckInTime());
Long lastCheckInTimestamp = MiscUtil.asMillis(node.getLastCheckInTime());
return lastCheckInTimestamp == null ||
System.currentTimeMillis() > lastCheckInTimestamp + secondsLimit * 1000L;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
import java.util.Collection;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.exception.ConfigurationException;

import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityCollectionType;

import org.apache.directory.api.ldap.model.cursor.CursorException;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapException;
Expand Down Expand Up @@ -48,8 +44,10 @@
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityCollectionType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

Expand Down Expand Up @@ -420,7 +418,7 @@ public void test200AssignAccountBarbossa() throws Exception {
String accountBarbossaIcfUid = (String) identifiers.iterator().next().getRealValue();
assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);

assertEquals("Wrong ICFS UID", MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes()), accountBarbossaIcfUid);
assertEquals("Wrong ICFS UID", MiscUtil.bytesToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes()), accountBarbossaIcfUid);

assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_PASSWORD);
assertPasswordAllowChange(shadow, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public void test200AssignAccountBarbossa() throws Exception {
assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);

assertEquals("Wrong ICFS UID",
formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
formatGuidToDashedNotation(MiscUtil.bytesToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
accountBarbossaIcfUid);

assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
Expand Down Expand Up @@ -1998,7 +1998,7 @@ public void test600AssignAccountSubman() throws Exception {
assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);

assertEquals("Wrong ICFS UID",
formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
formatGuidToDashedNotation(MiscUtil.bytesToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
accountBarbossaIcfUid);

assertLdapPassword(getSubLdapConnectionConfig(), USER_SUBMAN_USERNAME, USER_SUBMAN_FULL_NAME, USER_SUBMAN_PASSWORD);
Expand Down Expand Up @@ -2235,7 +2235,7 @@ public void test700AssignAccountSubmarineAndModify() throws Exception {
assertNotNull("No identifier in " + shadow, accountIcfUid);

assertEquals("Wrong ICFS UID",
formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
formatGuidToDashedNotation(MiscUtil.bytesToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
accountIcfUid);

assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public void test200AssignAccountBarbossa() throws Exception {
assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);

assertEquals("Wrong ICFS UID",
formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
formatGuidToDashedNotation(MiscUtil.bytesToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())),
accountBarbossaIcfUid);

assertLdapPasswordByFullName(USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void test202AssignLdapAccountToGuybrush() throws Exception {
OperationResult result = task.getResult();

byte[] photoIn = Files.readAllBytes(Paths.get(DOT_JPG_FILENAME));
displayValue("Photo in", MiscUtil.binaryToHex(photoIn));
displayValue("Photo in", MiscUtil.bytesToHex(photoIn));
modifyUserReplace(USER_GUYBRUSH_OID, UserType.F_JPEG_PHOTO, task, result, photoIn);

Collection<SelectorOptions<GetOperationOptions>> options = getOperationOptionsBuilder()
Expand Down Expand Up @@ -205,7 +205,7 @@ public void test202AssignLdapAccountToGuybrush() throws Exception {
PrismProperty<byte[]> jpegPhotoAttr = attributesContainer.findProperty(jpegPhotoQName);
byte[] photoBytesOut = jpegPhotoAttr.getValues().get(0).getValue();

displayValue("Photo bytes out", MiscUtil.binaryToHex(photoBytesOut));
displayValue("Photo bytes out", MiscUtil.bytesToHex(photoBytesOut));

assertEquals("Photo byte length changed (shadow)", photoIn.length, photoBytesOut.length);
assertTrue("Photo bytes do not match (shadow)", Arrays.equals(photoIn, photoBytesOut));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,6 @@ protected void assertModifyTimestamp(PrismObject<ShadowType> shadow, long startT

protected Long getTimestampAttribute(PrismObject<ShadowType> shadow) throws Exception {
XMLGregorianCalendar attributeValue = ShadowUtil.getAttributeValue(shadow, OPENDJ_MODIFY_TIMESTAMP_ATTRIBUTE_QNAME);
return MiscUtil.asLong(attributeValue);
return MiscUtil.asMillis(attributeValue);
}
}

0 comments on commit 3a96def

Please sign in to comment.