Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Apr 11, 2018
2 parents 0a3b3d9 + 18cebea commit cda6af5
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 52 deletions.
Expand Up @@ -24,6 +24,8 @@
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.objectdetails.FocusMainPanel;
import com.evolveum.midpoint.web.component.prism.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -85,6 +87,8 @@ public abstract class AssignmentPanel extends BasePanel<ContainerWrapper<Assignm
private final static String ID_DONE_BUTTON = "doneButton";
private final static String ID_CANCEL_BUTTON = "cancelButton";

private static final Trace LOGGER = TraceManager.getTrace(AssignmentPanel.class);

protected boolean assignmentDetailsVisible;
private List<ContainerValueWrapper<AssignmentType>> detailsPanelAssignmentsList = new ArrayList<>();

Expand Down Expand Up @@ -184,7 +188,8 @@ protected List<ContainerValueWrapper<AssignmentType>> searchThroughList() {
};

List<IColumn<ContainerValueWrapper<AssignmentType>, String>> columns = initBasicColumns();
columns.add(new InlineMenuButtonColumn<>(getAssignmentMenuActions(), 2, getPageBase()));
List<InlineMenuItem> menuActionsList = getAssignmentMenuActions();
columns.add(new InlineMenuButtonColumn<>(menuActionsList, menuActionsList.size(), getPageBase()));

BoxedTablePanel<ContainerValueWrapper<AssignmentType>> assignmentTable = new BoxedTablePanel<ContainerValueWrapper<AssignmentType>>(ID_ASSIGNMENTS_TABLE,
assignmentsProvider, columns, getTableId(), getItemsPerPage()) {
Expand Down Expand Up @@ -374,11 +379,30 @@ private List<ContainerValueWrapper<AssignmentType>> getSelectedAssignments() {

private List<InlineMenuItem> getAssignmentMenuActions() {
List<InlineMenuItem> menuItems = new ArrayList<>();
menuItems.add(new InlineMenuItem(createStringResource("PageBase.button.unassign"), new Model<>(true),
new Model<>(true), false, createDeleteColumnAction(), 0, GuiStyleConstants.CLASS_DELETE_MENU_ITEM,
DoubleButtonColumn.BUTTON_COLOR_CLASS.DANGER.toString()));
PrismObject obj = getFocusObject();
boolean isUnassignMenuAdded = false;
try {
boolean isUnassignAuthorized = getParentPage().isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_UNASSIGN_ACTION_URI,
AuthorizationPhaseType.REQUEST, obj,
null, null, null);
if (isUnassignAuthorized) {
menuItems.add(new InlineMenuItem(createStringResource("PageBase.button.unassign"), new Model<>(true),
new Model<>(true), false, createDeleteColumnAction(), 0, GuiStyleConstants.CLASS_DELETE_MENU_ITEM,
DoubleButtonColumn.BUTTON_COLOR_CLASS.DANGER.toString()));
isUnassignMenuAdded = true;
}

} catch (Exception ex){
LOGGER.error("Couldn't check unassign authorization for the object: {}, {}", obj.getName(), ex.getLocalizedMessage());
if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_ASSIGN_ACTION_URI)){
menuItems.add(new InlineMenuItem(createStringResource("PageBase.button.unassign"), new Model<>(true),
new Model<>(true), false, createDeleteColumnAction(), 0, GuiStyleConstants.CLASS_DELETE_MENU_ITEM,
DoubleButtonColumn.BUTTON_COLOR_CLASS.DANGER.toString()));
isUnassignMenuAdded = true;
}
}
menuItems.add(new InlineMenuItem(createStringResource("PageBase.button.edit"), new Model<>(true),
new Model<>(true), false, createEditColumnAction(), 1, GuiStyleConstants.CLASS_EDIT_MENU_ITEM,
new Model<>(true), false, createEditColumnAction(), isUnassignMenuAdded ? 1 : 0, GuiStyleConstants.CLASS_EDIT_MENU_ITEM,
DoubleButtonColumn.BUTTON_COLOR_CLASS.DEFAULT.toString()));
return menuItems;
}
Expand Down
Expand Up @@ -152,66 +152,81 @@ public static String debugDump() {
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid,
Collection<SelectorOptions<GetOperationOptions>> options, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {

if (supportsGlobalCaching(type, options)) {
CacheKey key = new CacheKey(type, oid);
CacheObject<T> cacheObject = globalCache.get(key);
if (cacheObject == null) {
return reloadObject(key, options, parentResult);
}

if (!shouldCheckVersion(cacheObject)) {
log("Cache: Global HIT {}", key);
return cacheObject.getObject();
}

if (hasVersionChanged(key, cacheObject, parentResult)) {
return reloadObject(key, options, parentResult);
}

// version matches, renew ttl
cacheObject.setTimeToLive(System.currentTimeMillis() + cacheMaxTTL);

log("Cache: Global HIT, version check {}", key);
return cacheObject.getObject();
}
boolean readOnly = GetOperationOptions.isReadOnly(SelectorOptions.findRootOptions(options));

if (!isCacheable(type) || !nullOrHarmlessOptions(options)) {
// local cache not interested in caching this object
log("Cache: PASS {} ({})", oid, type.getSimpleName());
Long startTime = repoOpStart();
try {
return repositoryService.getObject(type, oid, options, parentResult);
} finally {
repoOpEnd(startTime);
}


PrismObject<T> object = getObjectTryGlobalCache(type, oid, options, parentResult);
return cloneIfNecessary(object, readOnly);
}

Cache cache = getCache();
boolean readOnly = GetOperationOptions.isReadOnly(SelectorOptions.findRootOptions(options));
if (cache == null) {
log("Cache: NULL {} ({})", oid, type.getSimpleName());
} else {
PrismObject<T> object = (PrismObject) cache.getObject(oid);
if (object != null) {
// TODO: result?
if (readOnly) {
log("Cache: HIT {} ({})", oid, type.getSimpleName());
return object;
} else {
log("Cache: HIT(clone) {} ({})", oid, type.getSimpleName());
return object.clone();
}
log("Cache: HIT{} {} ({})", readOnly ? "" : "(clone)", oid, type.getSimpleName());
return cloneIfNecessary(object, readOnly);
}
log("Cache: MISS {} ({})", oid, type.getSimpleName());
}
PrismObject<T> object;

PrismObject<T> object = getObjectTryGlobalCache(type, oid, options, parentResult);
cacheObject(cache, object, readOnly);

return cloneIfNecessary(object, readOnly);
}

private <T extends ObjectType> PrismObject<T> cloneIfNecessary(PrismObject<T> object, boolean readOnly) {
if (readOnly) {
return object;
}

return object.clone();
}

private <T extends ObjectType> PrismObject<T> getObjectTryGlobalCache(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options,
OperationResult parentResult) throws SchemaException, ObjectNotFoundException {

if (!supportsGlobalCaching(type, options)) {
// caller is not interested in cached value, or global cache doesn't want to cache value
return getObjectInternal(type, oid, options, parentResult);
}

CacheKey key = new CacheKey(type, oid);
CacheObject<T> cacheObject = globalCache.get(key);

if (cacheObject == null) {
return reloadObject(key, options, parentResult);
}

if (!shouldCheckVersion(cacheObject)) {
log("Cache: Global HIT {}", key);
return cacheObject.getObject();
}

if (hasVersionChanged(key, cacheObject, parentResult)) {
return reloadObject(key, options, parentResult);
}

// version matches, renew ttl
cacheObject.setTimeToLive(System.currentTimeMillis() + cacheMaxTTL);

log("Cache: Global HIT, version check {}", key);
return cacheObject.getObject();
}

private <T extends ObjectType> PrismObject<T> getObjectInternal(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options,
OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
Long startTime = repoOpStart();
try {
object = repositoryService.getObject(type, oid, null, parentResult);
return repositoryService.getObject(type, oid, options, parentResult);
} finally {
repoOpEnd(startTime);
}
cacheObject(cache, object, readOnly);
return object;
}

private Long repoOpStart() {
Expand Down Expand Up @@ -791,7 +806,7 @@ private <T extends ObjectType> PrismObject<T> reloadObject(
log("Cache: Global MISS {}", key);

try {
PrismObject object = repositoryService.getObject(key.getType(), key.getOid(), options, result);
PrismObject object = getObjectInternal(key.getType(), key.getOid(), options, result);

long ttl = System.currentTimeMillis() + cacheMaxTTL;
CacheObject<T> cacheObject = new CacheObject<>(object, ttl);
Expand Down
Expand Up @@ -970,9 +970,8 @@ public void test506generateHonorificPrefixNameExecute() throws Exception {
private OperationResult traceResponse(Response response) throws SchemaException {
if (response.getStatus() != 200 && response.getStatus() != 201 && response.getStatus() != 204) {
OperationResultType result = response.readEntity(OperationResultType.class);
LOGGER.info("####RESULT");
OperationResult opResult = OperationResult.createOperationResult(result);
LOGGER.info(opResult.debugDump());
display("REST result", opResult);
return opResult;
}

Expand Down
@@ -0,0 +1,13 @@
{
"@ns": "http://midpoint.evolveum.com/xml/ns/public/common/api-types-3",
"objectModification" : {
"itemDelta" : [{
"@ns": "http://prism.evolveum.com/xml/ns/public/types-3",
"modificationType" : "replace",
"path" : "credentials/securityQuestions/questionAnswer[1]/questionAnswer",
"value" : {
"clearValue" : "newAnswer"
}
}]
}
}
Expand Up @@ -4,9 +4,13 @@
"itemDelta" : [{
"@ns": "http://prism.evolveum.com/xml/ns/public/types-3",
"modificationType" : "replace",
"path" : "credentials/securityQuestions/questionAnswer[1]/questionAnswer",
"path" : "credentials/securityQuestions/questionAnswer",
"value" : {
"clearValue" : "newAnswer"
"@ns": "http://midpoint.evolveum.com/xml/ns/public/common/common-3",
"questionIdentifier" : "http://midpoint.evolveum.com/xml/ns/public/security/question-2#q001",
"questionAnswer" : {
"clearValue" : "you would not believe what happens next"
}
}
}]
}
Expand Down
@@ -0,0 +1,10 @@
{
"@ns": "http://midpoint.evolveum.com/xml/ns/public/common/api-types-3",
"objectModification" : {
"itemDelta" : [{
"@ns": "http://prism.evolveum.com/xml/ns/public/types-3",
"modificationType" : "replace",
"path" : "credentials/securityQuestions/questionAnswer"
}]
}
}
@@ -0,0 +1,26 @@
{
"@ns": "http://midpoint.evolveum.com/xml/ns/public/common/api-types-3",
"objectModification" : {
"itemDelta" : [{
"@ns": "http://prism.evolveum.com/xml/ns/public/types-3",
"modificationType" : "replace",
"path" : "credentials/securityQuestions/questionAnswer",
"value" : [
{
"@ns": "http://midpoint.evolveum.com/xml/ns/public/common/common-3",
"questionIdentifier" : "http://midpoint.evolveum.com/xml/ns/public/security/question-2#q001",
"questionAnswer" : {
"clearValue" : "yet another answer"
}
},
{
"@ns": "http://midpoint.evolveum.com/xml/ns/public/common/common-3",
"questionIdentifier" : "http://midpoint.evolveum.com/xml/ns/public/security/question-2#q002",
"questionAnswer" : {
"clearValue" : "42"
}
}
]
}]
}
}

0 comments on commit cda6af5

Please sign in to comment.