/*
Check the SPARQLUpdate statements for the invalid interaction model changes.
@param request the UpdateRequest
@throws InteractionModelViolationException when attempting to change the interaction model
345791
private void checkInteractionModel(final UpdateRequest request)  {
        final List<Quad> deleteQuads = new ArrayList<>();
        final List<Quad> updateQuads = new ArrayList<>();

        for (final Update operation : request.getOperations()) {
            if (operation instanceof UpdateModify) {
                final UpdateModify op = (UpdateModify) operation;
                deleteQuads.addAll(op.getDeleteQuads());
                updateQuads.addAll(op.getInsertQuads());
            } else if (operation instanceof UpdateData) {
                final UpdateData op = (UpdateData) operation;
                updateQuads.addAll(op.getQuads());
            } else if (operation instanceof UpdateDeleteWhere) {
                final UpdateDeleteWhere op = (UpdateDeleteWhere) operation;
                deleteQuads.addAll(op.getQuads());
            }

            final Optional<String> resourceInteractionModel = getResourceInteraction();
            if (resourceInteractionModel.isPresent()) {
                updateQuads.forEach(e -> {
                    // check for interaction model change violation
                    checkInteractionModel(e.asTriple(), resourceInteractionModel);
                });
            }

            deleteQuads.forEach(e -> {
                final String interactionModel = getInteractionModel.apply(e.asTriple());
                if (StringUtils.isNotBlank(interactionModel)) {
                    throw new InteractionModelViolationException("Deleting the interaction model "
                            + interactionModel + " is not allowed!");
                }
            });
        }
    }
162734
public static <T> void validate(Request<T> request) throws ValidationConstraintViolationException {
		if (request != null) {
			Class<?> clazz = request.getClass();
			List<ConstraintViolation> leafs = new LinkedList<ConstraintViolation>();

			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				if (null != field.getAnnotation(Required.class)) {

					field.setAccessible(true);
					Object value = null;
					try {
						value = field.get(request);
					} catch (Exception e) {
						// not cool...
						throw new ValidationConstraintViolationException(e);
					}

					if (value == null || value instanceof String && ((String) value).isEmpty()) {
						ConstraintViolation violation = ConstraintViolation.newConstraintViolation("@" + Required.class.getSimpleName(), field);
						leafs.add(violation);
					}
				}
			}

			if (!leafs.isEmpty()) {
				throw new ValidationConstraintViolationException(preMessage, leafs);
			}
		}
	}
1287140
public void sendUpdateQuery(String queryString, SPARQLQueryBindingSet bindings, boolean includeInferred, String baseURI) throws IOException, RepositoryException, MalformedQueryException,UpdateExecutionException {
		getClient().performUpdateQuery(queryString, bindings, this.tx, includeInferred, baseURI);
	}
1241703
private void addQueryParams(final Request request) {
        if (recurring != null) {
            request.addQueryParam("Recurring", recurring.toString());
        }

        if (triggerBy != null) {
            request.addQueryParam("TriggerBy", triggerBy.toString());
        }

        if (usageCategory != null) {
            request.addQueryParam("UsageCategory", usageCategory.toString());
        }

        if (getPageSize() != null) {
            request.addQueryParam("PageSize", Integer.toString(getPageSize()));
        }
    }
1294971
public static void updateDirectEditFlagInSession(ServletRequest request) {

        String disabledParam = request.getParameter(CmsGwtConstants.PARAM_DISABLE_DIRECT_EDIT);
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(disabledParam)) {
            if (Boolean.parseBoolean(disabledParam)) {
                ((HttpServletRequest)request).getSession().setAttribute(
                    CmsGwtConstants.PARAM_DISABLE_DIRECT_EDIT,
                    Boolean.TRUE);
                String buttonLeft = request.getParameter(CmsGwtConstants.PARAM_BUTTON_LEFT);
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(buttonLeft)) {
                    Integer left = null;
                    try {
                        left = Integer.valueOf(buttonLeft);
                        if (left.intValue() > 0) {
                            ((HttpServletRequest)request).getSession().setAttribute(
                                CmsGwtConstants.PARAM_BUTTON_LEFT,
                                left);
                        }
                    } catch (NumberFormatException e) {
                        // malformed parameter, ignore
                    }
                }
            } else {
                ((HttpServletRequest)request).getSession().removeAttribute(CmsGwtConstants.PARAM_DISABLE_DIRECT_EDIT);
            }
        }
    }
1196433
private void addQueryParams(final Request request) {
        if (status != null) {
            request.addQueryParam("Status", status.toString());
        }

        if (phoneNumber != null) {
            request.addQueryParam("PhoneNumber", phoneNumber.toString());
        }

        if (incomingPhoneNumberSid != null) {
            request.addQueryParam("IncomingPhoneNumberSid", incomingPhoneNumberSid);
        }

        if (friendlyName != null) {
            request.addQueryParam("FriendlyName", friendlyName);
        }

        if (uniqueName != null) {
            request.addQueryParam("UniqueName", uniqueName);
        }

        if (getPageSize() != null) {
            request.addQueryParam("PageSize", Integer.toString(getPageSize()));
        }
    }
194979
@Override
	protected void preparePaintComponent(final Request request) {
		super.preparePaintComponent(request);
		if (!isInitialised()) {
			table.setTableModel(createTableModel());
			setInitialised(true);
		}
	}
818047
private void addQueryParams(final Request request) {
        if (order != null) {
            request.addQueryParam("Order", order.toString());
        }

        if (from != null) {
            request.addQueryParam("From", from);
        }

        if (bounds != null) {
            request.addQueryParam("Bounds", bounds.toString());
        }

        if (getPageSize() != null) {
            request.addQueryParam("PageSize", Integer.toString(getPageSize()));
        }
    }
190358
private void updateRelationship( CmdbRequest request ) {
        if( !StringUtils.isEmpty( request.getConfigurationItemBusServName() ) ) {
            Cmdb busServiceItem = cmdbRepository.findByConfigurationItemAndItemType(request.getConfigurationItemBusServName(), APP_TYPE);

            if (busServiceItem.getComponents() == null){
                List<String> components =  new ArrayList<>();
                components.add(request.getConfigurationItem());

                busServiceItem.setComponents(components);
            }else{
                busServiceItem.getComponents().add(request.getConfigurationItem());
            }

            cmdbRepository.save( busServiceItem );
        }
    }
644625
private static DeleteRequestType checkType(
			final HttpServletRequest request,
			final DeleteResponse deleteResponse) {
		{
			final String sType = request
					.getParameter(ProtocolConstants.Parameters.Delete.TYPE);
			if (sType != null) {
				if (DeleteRequestType.USER.getIdentifier().equals(sType)) {
					return DeleteRequestType.USER;
				} else if (DeleteRequestType.FOLLOW.getIdentifier().equals(
						sType)) {
					return DeleteRequestType.FOLLOW;
				} else if (DeleteRequestType.STATUS_UPDATE.getIdentifier()
						.equals(sType)) {
					return DeleteRequestType.STATUS_UPDATE;
				} else {
					deleteResponse.typeInvalid(sType);
				}
			} else {
				deleteResponse.typeMissing();
			}

			return null;
		}

	}
578460
private void addPostParams(final Request request) {
        if (status != null) {
            request.addPostParam("Status", status.toString());
        }

        if (pauseBehavior != null) {
            request.addPostParam("PauseBehavior", pauseBehavior);
        }
    }
92025
@Override
	public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) {
		if (!Constants.PARAM_HISTORY.equals(theRequest.getOperation())) {
			return false;
		}
		if (theRequest.getResourceName() == null) {
			return myResourceOperationType == RestOperationTypeEnum.HISTORY_SYSTEM;
		}
		if (!StringUtils.equals(theRequest.getResourceName(), myResourceName)) {
			return false;
		}

		boolean haveIdParam = theRequest.getId() != null && !theRequest.getId().isEmpty();
		boolean wantIdParam = myIdParamIndex != null;
		if (haveIdParam != wantIdParam) {
			return false;
		}

		if (theRequest.getId() == null) {
			return myResourceOperationType == RestOperationTypeEnum.HISTORY_TYPE;
		} else if (theRequest.getId().hasVersionIdPart()) {
			return false;
		}

		return true;
	}
176655
private void addQueryParams(final Request request) {
        if (bindingType != null) {
            for (UserBinding.BindingType prop : bindingType) {
                request.addQueryParam("BindingType", prop.toString());
            }
        }

        if (getPageSize() != null) {
            request.addQueryParam("PageSize", Integer.toString(getPageSize()));
        }
    }
1156996
@Override
	public void serviceRequest(final Request request) {
		LOG.debug("Before Service Request - Clearing targetable index.");
		UIContext uic = UIContextHolder.getCurrent();

		super.serviceRequest(request);
		// Clear phase scope scratch map
		LOG.debug("After Service Request - Clearing scratch map with phase scope.");
		uic.clearScratchMap();
	}
911583
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public ResponseEntity<E> update(@PathVariable int id, HttpServletRequest request) {

        String errorPrefix = "Error updating "
            + getEntityClass().getSimpleName() + " with ID " + id + ": ";

        Reader reader = null;

        try {
            // read and parse the json request body
            reader = request.getReader();
            JsonNode jsonObject = objectMapper.readTree(reader);

            // validate json object
            if (jsonObject == null || !jsonObject.has("id")) {
                LOG.error(errorPrefix
                    + "The JSON body is empty or has no 'id' property.");
                return new ResponseEntity<E>(HttpStatus.BAD_REQUEST);
            }

            // assure that the path variable id equals the payload id
            final int payloadId = jsonObject.get("id").asInt();
            if (payloadId != id) {
                LOG.error(errorPrefix + "Requested to update entity with ID "
                    + id + ", but payload ID is " + payloadId);
                return new ResponseEntity<E>(HttpStatus.BAD_REQUEST);
            }

            // get the persisted entity
            E entity = service.findById(id);

            if (entity != null) {
                // we call this transactional method (instead of save or update)
                // to make sure that the possibly modified entity does not
                // get persisted / synced unexpectedly by hibernate
                // (due to FlushMode.AUTO) when another database-related
                // interaction is triggered in the meantime (which could happen
                // for example in a permission evaluation).
                // In other words: Do not get an entity, modify it and save it
                // in a non-transactional way (e.g. controller method), as
                // a possible permission evaluation could trigger an unwanted
                // persist action before the permission was evaluated.
                entity = service.updatePartialWithJsonNode(entity, jsonObject, objectMapper);
                return new ResponseEntity<E>(entity, HttpStatus.OK);
            }
            return new ResponseEntity<E>(HttpStatus.NOT_FOUND);
        } catch (Exception e) {
            LOG.error(errorPrefix + e.getMessage());
            return new ResponseEntity<E>(HttpStatus.NOT_FOUND);
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
849318
private void addQueryParams(final Request request) {
        if (beta != null) {
            request.addQueryParam("Beta", beta.toString());
        }

        if (friendlyName != null) {
            request.addQueryParam("FriendlyName", friendlyName);
        }

        if (phoneNumber != null) {
            request.addQueryParam("PhoneNumber", phoneNumber.toString());
        }

        if (origin != null) {
            request.addQueryParam("Origin", origin);
        }

        if (getPageSize() != null) {
            request.addQueryParam("PageSize", Integer.toString(getPageSize()));
        }
    }
158921
private void handleExpansionRequest(final Request request) {
		String[] paramValue = request.getParameterValues(getId() + ".expanded");

		if (paramValue == null) {
			paramValue = new String[0];
		}

		Map<List<Integer>, Object> pageRowKeys = getCurrentRowIndexAndKeys();

		String[] expandedRows = removeEmptyStrings(paramValue);
		Set<?> oldExpansions = getExpandedRows();
		Set<Object> newExpansions;

		TableModel model = getTableModel();

		if (model.getRowCount() == 0) {
			newExpansions = new HashSet<>();
			expandedRows = new String[0];
		} else if (getPaginationMode() == PaginationMode.NONE || getPaginationMode() == PaginationMode.CLIENT
				|| oldExpansions == null || !isPaginated()) {
			newExpansions = new HashSet<>(expandedRows.length);
		} else {
			// row expansions only apply to the current page
			newExpansions = (Set<Object>) new HashSet<>(oldExpansions);
			newExpansions.removeAll(pageRowKeys.values());
		}

		for (String expandedRow : expandedRows) {
			List<Integer> rowIndex = TableUtil.rowIndexStringToList(expandedRow);
			Object key = pageRowKeys.get(rowIndex);
			if (key != null) {
				newExpansions.add(key);
			}
		}

		setExpandedRows(newExpansions);
	}