Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 5, 2021
2 parents a8d0c7f + 00ba8a9 commit 560f505
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4207,6 +4207,12 @@ public static List<AssignmentObjectRelation> divideAssignmentRelationsByAllValue
if (CollectionUtils.isNotEmpty(assignmentObjectRelation.getObjectTypes())) {
assignmentObjectRelation.getObjectTypes().forEach(objectType -> {
if (CollectionUtils.isNotEmpty(assignmentObjectRelation.getArchetypeRefs())) {
//add at first type+relation combination without archetypeRef to cover default views (e.g. all users)
AssignmentObjectRelation defaultViewRelation = new AssignmentObjectRelation();
defaultViewRelation.setObjectTypes(Collections.singletonList(objectType));
defaultViewRelation.setRelations(assignmentObjectRelation.getRelations());
defaultViewRelation.setDescription(assignmentObjectRelation.getDescription());
resultList.add(defaultViewRelation);
assignmentObjectRelation.getArchetypeRefs().forEach(archetypeRef -> {
AssignmentObjectRelation newRelation = new AssignmentObjectRelation();
newRelation.setObjectTypes(Collections.singletonList(objectType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ protected List<ObjectReferenceType> getNewObjectReferencesList(CompiledObjectCol
if (refList == null) {
refList = new ArrayList<>();
}
if (relation != null && CollectionUtils.isNotEmpty(relation.getArchetypeRefs())) {
refList.addAll(relation.getArchetypeRefs());
}
ObjectReferenceType membershipRef = new ObjectReferenceType();
membershipRef.setOid(AbstractRoleMemberPanel.this.getModelObject().getOid());
membershipRef.setType(AbstractRoleMemberPanel.this.getModelObject().asPrismObject().getComplexTypeDefinition().getTypeName());
Expand Down Expand Up @@ -544,6 +547,7 @@ protected List<AssignmentObjectRelation> getDefaultNewMemberRelations() {
AssignmentObjectRelation assignmentObjectRelation = new AssignmentObjectRelation();
assignmentObjectRelation.addRelations(supportedRelation);
assignmentObjectRelation.addObjectTypes(Collections.singletonList(objectType));
assignmentObjectRelation.getArchetypeRefs().addAll(archetypeReferencesListForType(objectType));
relationsList.add(assignmentObjectRelation);
});
} else {
Expand All @@ -554,6 +558,18 @@ protected List<AssignmentObjectRelation> getDefaultNewMemberRelations() {
return relationsList;
}

private List<ObjectReferenceType> archetypeReferencesListForType(QName type) {
List<CompiledObjectCollectionView> views =
getPageBase().getCompiledGuiProfile().findAllApplicableArchetypeViews(type, OperationTypeType.ADD);
List<ObjectReferenceType> archetypeRefs = new ArrayList<>();
views.forEach(view -> {
if (view.getCollection() != null && view.getCollection().getCollectionRef() != null) {
archetypeRefs.add(view.getCollection().getCollectionRef());
}
});
return archetypeRefs;
}

private AjaxIconButton createAssignButton(String buttonId) {
AjaxIconButton assignButton = new AjaxIconButton(buttonId, new Model<>(GuiStyleConstants.EVO_ASSIGNMENT_ICON),
createStringResource("MainObjectListPanel.newObject")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ public String getNewValue() {

public List<SceneItemLineDto> computeLines() {
List<SceneItemLineDto> rv = new ArrayList<>();
int index = 0;
Collator collator = WebComponentUtil.getCollator();
if (!isDelta()) {
for (SceneItemValue itemValue : sceneItem.getNewValues()) {
rv.add(new SceneItemLineDto(this, null, itemValue, index++, false));
rv.add(new SceneItemLineDto(this, null, itemValue, false));
}
} else {
SceneDeltaItem deltaItem = (SceneDeltaItem) sceneItem;
for (SceneItemValue itemValue : deltaItem.getUnchangedValues()) {
rv.add(new SceneItemLineDto(this, null, itemValue, index++, false));
rv.add(new SceneItemLineDto(this, null, itemValue, false));
}
List<? extends SceneItemValue> deletedValues = deltaItem.getDeletedValues();
List<? extends SceneItemValue> addedValues = deltaItem.getAddedValues();
Expand All @@ -91,7 +90,7 @@ public List<SceneItemLineDto> computeLines() {
while (deletedValuesIter.hasNext() || addedValuesIter.hasNext()) {
SceneItemValue deletedValue = deletedValuesIter.hasNext() ? deletedValuesIter.next() : null;
SceneItemValue addedValue = addedValuesIter.hasNext() ? addedValuesIter.next() : null;
rv.add(new SceneItemLineDto(this, deletedValue, addedValue, index++, true));
rv.add(new SceneItemLineDto(this, deletedValue, addedValue, true));
}
}
Comparator<? super SceneItemLineDto> comparator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ public class SceneItemLineDto implements Serializable {
private final SceneItemDto sceneItemDto;
private final SceneItemValue sceneItemOldValue;
private final SceneItemValue sceneItemNewValue;
private final int index;
private final boolean isDelta;

public SceneItemLineDto(SceneItemDto sceneItemDto, SceneItemValue sceneItemOldValue, SceneItemValue sceneItemNewValue, int index, boolean isDelta) {
public SceneItemLineDto(SceneItemDto sceneItemDto, SceneItemValue sceneItemOldValue, SceneItemValue sceneItemNewValue, boolean isDelta) {
this.sceneItemDto = sceneItemDto;
this.sceneItemOldValue = sceneItemOldValue;
this.sceneItemNewValue = sceneItemNewValue;
this.index = index;
this.isDelta = isDelta;
}

Expand All @@ -52,7 +50,7 @@ public Integer getNumberOfLines() {
}

public boolean isFirst() {
return index == 0;
return sceneItemDto.getLines().indexOf(this) == 0;
}

public boolean isDelta() {
Expand Down Expand Up @@ -91,7 +89,6 @@ public boolean equals(Object o) {

SceneItemLineDto that = (SceneItemLineDto) o;

if (index != that.index) return false;
if (isDelta != that.isDelta) return false;
if (sceneItemOldValue != null ? !sceneItemOldValue.equals(that.sceneItemOldValue) : that.sceneItemOldValue != null)
return false;
Expand All @@ -104,7 +101,6 @@ public int hashCode() {
int result = 1;
result = 31 * result + (sceneItemOldValue != null ? sceneItemOldValue.hashCode() : 0);
result = 31 * result + (sceneItemNewValue != null ? sceneItemNewValue.hashCode() : 0);
result = 31 * result + index;
result = 31 * result + (isDelta ? 1 : 0);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ protected List<ObjectReferenceType> getNewObjectReferencesList(CompiledObjectCol
if (refList == null) {
refList = new ArrayList<>();
}
if (relation != null && CollectionUtils.isNotEmpty(relation.getArchetypeRefs())) {
refList.addAll(relation.getArchetypeRefs());
}
ObjectReferenceType membershipRef = new ObjectReferenceType();
membershipRef.setOid(AbstractRoleMemberPanel.this.getModelObject().getOid());
membershipRef.setType(AbstractRoleMemberPanel.this.getModelObject().asPrismObject().getComplexTypeDefinition().getTypeName());
Expand Down Expand Up @@ -480,6 +483,7 @@ protected List<AssignmentObjectRelation> getDefaultNewMemberRelations() {
AssignmentObjectRelation assignmentObjectRelation = new AssignmentObjectRelation();
assignmentObjectRelation.addRelations(supportedRelation);
assignmentObjectRelation.addObjectTypes(Collections.singletonList(objectType));
assignmentObjectRelation.getArchetypeRefs().addAll(archetypeReferencesListForType(objectType));
relationsList.add(assignmentObjectRelation);
});
} else {
Expand All @@ -490,6 +494,18 @@ protected List<AssignmentObjectRelation> getDefaultNewMemberRelations() {
return relationsList;
}

private List<ObjectReferenceType> archetypeReferencesListForType(QName type) {
List<CompiledObjectCollectionView> views =
getPageBase().getCompiledGuiProfile().findAllApplicableArchetypeViews(type, OperationTypeType.ADD);
List<ObjectReferenceType> archetypeRefs = new ArrayList<>();
views.forEach(view -> {
if (view.getCollection() != null && view.getCollection().getCollectionRef() != null) {
archetypeRefs.add(view.getCollection().getCollectionRef());
}
});
return archetypeRefs;
}

private AjaxIconButton createAssignButton(String buttonId) {
AjaxIconButton assignButton = new AjaxIconButton(buttonId, new Model<>(GuiStyleConstants.EVO_ASSIGNMENT_ICON),
createStringResource("MainObjectListPanel.newObject")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class AssignmentObjectRelation implements DebugDumpable, ShortDumpable, S
private static final long serialVersionUID = 1L;

public List<QName> objectTypes;
public List<ObjectReferenceType> archetypeRefs;
public List<ObjectReferenceType> archetypeRefs = new ArrayList<>();
public List<QName> relations;
public String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
Expand All @@ -27,6 +28,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -115,6 +117,8 @@ public void unregister() {
*/
@NotNull private Map<String, ConnectorType> connectorBeanCache = new ConcurrentHashMap<>();

private Consumer<ConnectorType> notInRepoConsumer;

Collection<ConnectorFactory> getConnectorFactories() {
if (connectorFactories == null) {
String[] connectorFactoryBeanNames = springContext.getBeanNamesForType(ConnectorFactory.class);
Expand Down Expand Up @@ -435,54 +439,19 @@ public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, Operati

LOGGER.trace("Examining connector {}", foundConnector);



boolean inRepo = isInRepo(foundConnector, hostType, result);
if (inRepo) {
LOGGER.trace("Connector {} is in the repository, skipping", foundConnector);

} else {
LOGGER.trace("Connector {} not in the repository, adding", foundConnector);

if (foundConnector.getSchema() == null) {
LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector);
}

// Sanitize framework-supplied OID
if (StringUtils.isNotEmpty(foundConnector.getOid())) {
LOGGER.warn("Provisioning framework {} supplied OID for connector {}", foundConnector.getFramework(), foundConnector);
foundConnector.setOid(null);
}

// Store the connector object
String oid;
try {
prismContext.adopt(foundConnector);
oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result);
} catch (ObjectAlreadyExistsException e) {
// We don't specify the OID, therefore this should never
// happen
// Convert to runtime exception
LOGGER.error("Got ObjectAlreadyExistsException while not expecting it: {}", e.getMessage(), e);
result.recordFatalError(
"Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got ObjectAlreadyExistsException while not expecting it: "
+ e.getMessage(), e);
} catch (SchemaException e) {
// If there is a schema error it must be a bug. Convert to
// runtime exception
LOGGER.error("Got SchemaException while not expecting it: {}", e.getMessage(), e);
result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
if (notInRepoConsumer != null) {
notInRepoConsumer.accept(foundConnector);
}
foundConnector.setOid(oid);

// We need to "embed" connectorHost to the connectorType. The UCF does not
// have access to repository, therefore it cannot resolve it for itself
if (hostType != null) {
foundConnector.getConnectorHostRef().asReferenceValue().setObject(hostType.asPrismObject());
if (addConnectorToRepo(foundConnector, result, hostType)) {
discoveredConnectors.add(foundConnector);
LOGGER.info("Discovered new connector {}", foundConnector);
}

discoveredConnectors.add(foundConnector);
LOGGER.info("Discovered new connector {}", foundConnector);
}
}
}
Expand All @@ -491,6 +460,51 @@ public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, Operati
return discoveredConnectors;
}

/**
*
* @return true if connector was not present in repo and was added to it
*/
private boolean addConnectorToRepo(ConnectorType foundConnector, OperationResult result, ConnectorHostType hostType) {
LOGGER.trace("Connector {} not in the repository, adding", foundConnector);

if (foundConnector.getSchema() == null) {
LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector);
}

// Sanitize framework-supplied OID
if (StringUtils.isNotEmpty(foundConnector.getOid())) {
LOGGER.warn("Provisioning framework {} supplied OID for connector {}", foundConnector.getFramework(), foundConnector);
foundConnector.setOid(null);
}

// Store the connector object
String oid;
try {
prismContext.adopt(foundConnector);
oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result);
} catch (ObjectAlreadyExistsException e) {
if (isInRepo(foundConnector, hostType, result)) {
return false;
}
throw new SystemException("Connector was not present in repository, but add failed", e);
} catch (SchemaException e) {
// If there is a schema error it must be a bug. Convert to
// runtime exception
LOGGER.error("Got SchemaException while not expecting it: {}", e.getMessage(), e);
result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
}
foundConnector.setOid(oid);

// We need to "embed" connectorHost to the connectorType. The UCF does not
// have access to repository, therefore it cannot resolve it for itself
if (hostType != null) {
foundConnector.getConnectorHostRef().asReferenceValue().setObject(hostType.asPrismObject());
}
return true;

}

private boolean isInRepo(ConnectorType connectorType, ConnectorHostType hostType, OperationResult result) {
ObjectQuery query;
if (hostType == null) {
Expand Down Expand Up @@ -707,4 +721,9 @@ public void newConnectorDiscovered(ConnectorHostType host) {
LOGGER.error("Error occured during discovery of connectors");
}
}

@VisibleForTesting
void setNotFoundInRepoConsumer(Consumer<ConnectorType> consumer) {
this.notInRepoConsumer = consumer;
}
}

0 comments on commit 560f505

Please sign in to comment.