Skip to content

Commit

Permalink
refreshSchema method is moved to util class
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 12, 2018
1 parent 1c41970 commit aef27a6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 44 deletions.
Expand Up @@ -47,12 +47,14 @@
import com.evolveum.midpoint.gui.api.SubscriptionType;
import com.evolveum.midpoint.gui.api.model.ReadOnlyValueModel;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.util.ResourceUtils;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.query.builder.S_FilterEntryOrEmpty;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.util.LocalizationUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.*;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.web.component.breadcrumbs.Breadcrumb;
import com.evolveum.midpoint.web.component.breadcrumbs.BreadcrumbPageClass;
import com.evolveum.midpoint.web.component.breadcrumbs.BreadcrumbPageInstance;
Expand Down Expand Up @@ -140,8 +142,6 @@
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.TaskCategory;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -2583,6 +2583,25 @@ public static ItemVisibility checkShadowActivationAndPasswordVisibility(ItemWrap

}

public static void refreshResourceSchema(@NotNull PrismObject<ResourceType> resource, String operation, AjaxRequestTarget target, PageBase pageBase){
Task task = pageBase.createSimpleTask(operation);
OperationResult parentResult = new OperationResult(operation);

try {
ResourceUtils.deleteSchema(resource, pageBase.getModelService(), pageBase.getPrismContext(), task, parentResult);
pageBase.getModelService().testResource(resource.getOid(), task); // try to load fresh scehma
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Error refreshing resource schema", e);
parentResult.recordFatalError("Error refreshing resource schema", e);
}

parentResult.computeStatus();
pageBase.showResult(parentResult, "pageResource.refreshSchema.failed");
target.add(pageBase.getFeedbackPanel());
}

public static List<QName> getCategoryRelationChoices(AreaCategoryType category, ModelServiceLocator pageBase){
List<QName> relationsList = new ArrayList<>();
List<RelationDefinitionType> defList = getRelationDefinitions(pageBase);
Expand Down
Expand Up @@ -174,7 +174,7 @@ public void onClick(AjaxRequestTarget target) {

@Override
public void onClick(AjaxRequestTarget target) {
refreshSchemaPerformed(target);
WebComponentUtil.refreshResourceSchema(resourceModel.getObject(), OPERATION_REFRESH_SCHEMA, target, PageResource.this);
}
};
refreshSchema.add(new VisibleEnableBehaviour() {
Expand Down Expand Up @@ -364,27 +364,6 @@ protected void onTabChange(int index) {
}



private void refreshSchemaPerformed(AjaxRequestTarget target) {

Task task = createSimpleTask(OPERATION_REFRESH_SCHEMA);
OperationResult parentResult = new OperationResult(OPERATION_REFRESH_SCHEMA);

try {
ResourceUtils.deleteSchema(resourceModel.getObject(), getModelService(), getPrismContext(), task, parentResult);
getModelService().testResource(resourceModel.getObject().getOid(), task); // try to load fresh scehma
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Error refreshing resource schema", e);
parentResult.recordFatalError("Error refreshing resource schema", e);
}

parentResult.computeStatus();
showResult(parentResult, "pageResource.refreshSchema.failed");
target.add(getFeedbackPanel());
}

private void testConnectionPerformed(AjaxRequestTarget target) {
final PrismObject<ResourceType> dto = resourceModel.getObject();
if (dto == null || StringUtils.isEmpty(dto.getOid())) {
Expand Down
Expand Up @@ -383,31 +383,12 @@ private void refreshSchemaPerformed(ResourceType resource, AjaxRequestTarget tar
createStringResource("pageResources.message.refreshResourceSchemaConfirm")){
@Override
public void yesPerformed(AjaxRequestTarget target) {
refreshSchemaConfirmPerformed(resource, target);
WebComponentUtil.refreshResourceSchema(resource.asPrismObject(), OPERATION_REFRESH_SCHEMA, target, PageResources.this);
}
};
((PageBase)getPage()).showMainPopup(dialog, target);
}

private void refreshSchemaConfirmPerformed(ResourceType resource, AjaxRequestTarget target){
Task task = createSimpleTask(OPERATION_REFRESH_SCHEMA);
OperationResult parentResult = new OperationResult(OPERATION_REFRESH_SCHEMA);

try {
ResourceUtils.deleteSchema(resource.asPrismObject(), getModelService(), getPrismContext(), task, parentResult);
getModelService().testResource(resource.getOid(), task);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Error refreshing resource schema", e);
parentResult.recordFatalError("Error refreshing resource schema", e);
}

parentResult.computeStatus();
showResult(parentResult, "pageResource.refreshSchema.failed");
target.add(getFeedbackPanel());
}

private void deleteResourcePerformed(AjaxRequestTarget target, ResourceType single) {
List<ResourceType> selected = isAnyResourceSelected(target, single);
if (selected.size() < 1) {
Expand Down
Expand Up @@ -3505,6 +3505,7 @@ TaskSummaryPanel.rejected=Rejected
TaskSummaryPanel.approved=Approved
TaskSummaryPanel.unknown=Unknown
operation.com.evolveum.midpoint.web.page.admin.resources.PageResource.refreshSchema=Refresh schema (GUI)
operation.com.evolveum.midpoint.web.page.admin.resources.PageResources.refreshSchema=Refresh schema (GUI)
TaskDto.changesApplied=Changes applied (successfully or not)
TaskDto.changesBeingApplied=Changes being applied
TaskDto.changesWaitingToBeApplied=Changes waiting to be applied
Expand Down

0 comments on commit aef27a6

Please sign in to comment.