Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package org.apache.syncope.common.lib;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.syncope.common.lib.types.ClientExceptionType;

public class SyncopeClientCompositeException extends SyncopeClientException {
Expand All @@ -38,23 +38,8 @@ public boolean hasExceptions() {
return !exceptions.isEmpty();
}

public boolean hasException(final ClientExceptionType exceptionType) {
return getException(exceptionType) != null;
}

public SyncopeClientException getException(final ClientExceptionType exceptionType) {
boolean found = false;
SyncopeClientException syncopeClientException = null;
for (Iterator<SyncopeClientException> itor = exceptions.iterator(); itor.hasNext() && !found;) {
syncopeClientException = itor.next();
if (syncopeClientException.getType().equals(exceptionType)) {
found = true;
}
}

return found
? syncopeClientException
: null;
public Optional<SyncopeClientException> getException(final ClientExceptionType exceptionType) {
return exceptions.stream().filter(e -> e.getType() == exceptionType).findFirst();
}

public Set<SyncopeClientException> getExceptions() {
Expand All @@ -63,35 +48,22 @@ public Set<SyncopeClientException> getExceptions() {

public boolean addException(final SyncopeClientException exception) {
if (exception.getType() == null) {
throw new IllegalArgumentException(exception + " does not have the right "
+ ClientExceptionType.class.getName() + " set");
exception.setType(ClientExceptionType.Unknown);
}

Optional<SyncopeClientException> alreadyAdded =
exceptions.stream().filter(ex -> ex.getType() == exception.getType()).findFirst();

return alreadyAdded.map(e -> e.getElements()
.addAll(exception.getElements())).orElseGet(() -> exceptions.add(exception));
return exceptions.stream().
filter(e -> e.getType() == exception.getType()).findFirst().
map(e -> e.getElements().addAll(exception.getElements())).
orElseGet(() -> exceptions.add(exception));
}

@Override
public String getMessage() {
StringBuilder message = new StringBuilder();

message.append('{');
Iterator<SyncopeClientException> iter = getExceptions().iterator();
while (iter.hasNext()) {
SyncopeClientException e = iter.next();
message.append('[').
append(e.getMessage()).
append(']');
if (iter.hasNext()) {
message.append(", ");
}
}
message.append('}');

return message.toString();
return new StringBuilder().
append('{').
append(getExceptions().stream().map(e -> '[' + e.getMessage() + ']').collect(Collectors.joining(", "))).
append('}').
toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,99 @@
*/
package org.apache.syncope.common.lib.request;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.syncope.common.lib.to.RelationshipTO;
import org.apache.syncope.common.lib.Attr;

public class RelationshipUR extends AbstractPatch {

private static final long serialVersionUID = 1314175521205206511L;

public static class Builder extends AbstractPatch.Builder<RelationshipUR, Builder> {

public Builder(final RelationshipTO relationshipTO) {
public Builder(final String type) {
super();
getInstance().setRelationshipTO(relationshipTO);
getInstance().setType(type);
}

@Override
protected RelationshipUR newInstance() {
return new RelationshipUR();
}

public Builder otherEnd(final String type, final String key) {
getInstance().setOtherEndType(type);
getInstance().setOtherEndKey(key);
return this;
}

public Builder plainAttr(final Attr plainAttr) {
getInstance().getPlainAttrs().add(plainAttr);
return this;
}

public Builder plainAttrs(final Attr... plainAttrs) {
getInstance().getPlainAttrs().addAll(List.of(plainAttrs));
return this;
}

public Builder plainAttrs(final Collection<Attr> plainAttrs) {
getInstance().getPlainAttrs().addAll(plainAttrs);
return this;
}
}

private RelationshipTO relationshipTO;
private String type;

private String otherEndType;

private String otherEndKey;

private final Set<Attr> plainAttrs = new HashSet<>();

public String getType() {
return type;
}

public void setType(final String type) {
this.type = type;
}

public String getOtherEndType() {
return otherEndType;
}

public void setOtherEndType(final String otherEndType) {
this.otherEndType = otherEndType;
}

public String getOtherEndKey() {
return otherEndKey;
}

public RelationshipTO getRelationshipTO() {
return relationshipTO;
public void setOtherEndKey(final String otherEndKey) {
this.otherEndKey = otherEndKey;
}

public void setRelationshipTO(final RelationshipTO relationshipTO) {
this.relationshipTO = relationshipTO;
@JacksonXmlElementWrapper(localName = "plainAttrs")
@JacksonXmlProperty(localName = "plainAttr")
public Set<Attr> getPlainAttrs() {

Check notice

Code scanning / CodeQL

Exposing internal representation

getPlainAttrs exposes the internal representation stored in field plainAttrs. The value may be modified [after this call to getPlainAttrs](1).
return plainAttrs;
}

@Override
public int hashCode() {
return new HashCodeBuilder().
appendSuper(super.hashCode()).
append(relationshipTO).
append(type).
append(otherEndType).
append(otherEndKey).
build();
}

Expand All @@ -71,7 +128,9 @@
final RelationshipUR other = (RelationshipUR) obj;
return new EqualsBuilder().
appendSuper(super.equals(obj)).
append(relationshipTO, other.relationshipTO).
append(type, other.type).
append(otherEndType, other.otherEndType).
append(otherEndKey, other.otherEndKey).
build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@
*/
package org.apache.syncope.common.lib.to;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
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;
import org.apache.syncope.common.lib.Attr;
import org.apache.syncope.common.lib.BaseBean;

public class RelationshipTO implements BaseBean {
public class RelationshipTO implements BaseBean, AttributableTO {

private static final long serialVersionUID = 360672942026613929L;

Expand Down Expand Up @@ -59,6 +70,21 @@
return this;
}

public Builder plainAttr(final Attr plainAttr) {
instance.getPlainAttrs().add(plainAttr);
return this;
}

public Builder plainAttrs(final Attr... plainAttrs) {
instance.getPlainAttrs().addAll(List.of(plainAttrs));
return this;
}

public Builder plainAttrs(final Collection<Attr> plainAttrs) {
instance.getPlainAttrs().addAll(plainAttrs);
return this;
}

public RelationshipTO build() {
return instance;
}
Expand All @@ -74,6 +100,10 @@

private String otherEndName;

private final Set<Attr> plainAttrs = new TreeSet<>();

private final Set<Attr> derAttrs = new TreeSet<>();

public String getType() {
return type;
}
Expand Down Expand Up @@ -114,6 +144,32 @@
this.end = end;
}

@JacksonXmlElementWrapper(localName = "plainAttrs")
@JacksonXmlProperty(localName = "plainAttr")
@Override
public Set<Attr> getPlainAttrs() {

Check notice

Code scanning / CodeQL

Exposing internal representation

getPlainAttrs exposes the internal representation stored in field plainAttrs. The value may be modified [after this call to getPlainAttrs](1).
return plainAttrs;
}

@JsonIgnore
@Override
public Optional<Attr> getPlainAttr(final String schema) {
return plainAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
}

@JacksonXmlElementWrapper(localName = "derAttrs")
@JacksonXmlProperty(localName = "derAttr")
@Override
public Set<Attr> getDerAttrs() {

Check notice

Code scanning / CodeQL

Exposing internal representation

getDerAttrs exposes the internal representation stored in field derAttrs. The value may be modified [after this call to getDerAttrs](1).
return derAttrs;
}

@JsonIgnore
@Override
public Optional<Attr> getDerAttr(final String schema) {
return derAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst();
}

@Override
public int hashCode() {
return new HashCodeBuilder().
Expand All @@ -122,6 +178,8 @@
append(otherEndKey).
append(otherEndName).
append(end).
append(plainAttrs).
append(derAttrs).
build();
}

Expand All @@ -143,6 +201,18 @@
append(otherEndKey, other.otherEndKey).
append(otherEndName, other.otherEndName).
append(end, other.end).
append(plainAttrs, other.plainAttrs).
append(derAttrs, other.derAttrs).
build();
}

@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).
append(type).
append(end).
append(otherEndType).
append(otherEndKey).
build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
*/
package org.apache.syncope.common.lib.to;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import jakarta.ws.rs.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class RelationshipTypeTO implements EntityTO {

Expand All @@ -32,6 +38,8 @@

private String rightEndAnyType;

private final List<TypeExtensionTO> typeExtensions = new ArrayList<>();

@Override
public String getKey() {
return key;
Expand Down Expand Up @@ -66,4 +74,16 @@
public void setRightEndAnyType(final String rightEndAnyType) {
this.rightEndAnyType = rightEndAnyType;
}

@JsonIgnore
public Optional<TypeExtensionTO> getTypeExtension(final String anyType) {
return typeExtensions.stream().filter(
typeExtension -> anyType != null && anyType.equals(typeExtension.getAnyType())).findFirst();
}

@JacksonXmlElementWrapper(localName = "typeExtensions")
@JacksonXmlProperty(localName = "typeExtension")
public List<TypeExtensionTO> getTypeExtensions() {

Check notice

Code scanning / CodeQL

Exposing internal representation

getTypeExtensions exposes the internal representation stored in field typeExtensions. The value may be modified [after this call to getTypeExtensions](1). getTypeExtensions exposes the internal representation stored in field typeExtensions. The value may be modified [after this call to getTypeExtensions](2). getTypeExtensions exposes the internal representation stored in field typeExtensions. The value may be modified [after this call to getTypeExtensions](3).
return typeExtensions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
import org.apache.syncope.core.persistence.api.entity.Realm;
import org.apache.syncope.core.persistence.api.entity.group.Group;
import org.apache.syncope.core.persistence.api.entity.group.TypeExtension;
import org.apache.syncope.core.persistence.api.entity.group.GroupTypeExtension;
import org.apache.syncope.core.persistence.api.search.SyncopePage;
import org.apache.syncope.core.provisioning.api.data.GroupDataBinder;
import org.apache.syncope.core.spring.security.AuthContextUtils;
Expand Down Expand Up @@ -136,7 +136,7 @@ public TypeExtensionTO readTypeExtension(final String groupName) {
Group group = groupDAO.findByName(groupName).
orElseThrow(() -> new NotFoundException("Group " + groupName));

TypeExtension typeExt = group.getTypeExtension(anyTypeDAO.getUser()).
GroupTypeExtension typeExt = group.getTypeExtension(anyTypeDAO.getUser()).
orElseThrow(() -> new NotFoundException("TypeExtension in " + groupName + " for users"));

return groupDataBinder.getTypeExtensionTO(typeExt);
Expand Down
Loading
Loading