/** * Copy the A-fields to B-fields. The field bChanged is kept to false. */ public static ComponentUpdateDto copyFrom(ComponentDto from) { return new ComponentUpdateDto() .setUuid(from.uuid()) .setBChanged(false) .setBKey(from.getDbKey()) .setBCopyComponentUuid(from.getCopyResourceUuid()) .setBDescription(from.description()) .setBEnabled(from.isEnabled()) .setBUuidPath(from.getUuidPath()) .setBLanguage(from.language()) .setBLongName(from.longName()) .setBModuleUuid(from.moduleUuid()) .setBModuleUuidPath(from.moduleUuidPath()) .setBName(from.name()) .setBPath(from.path()) // We don't have a b_scope. The applyBChangesForRootComponentUuid query is using a case ... when to infer scope from the qualifier .setBQualifier(from.qualifier()); } }
private static Optional<ComponentUpdateDto> compareForUpdate(ComponentDto existing, ComponentDto target) { boolean hasDifferences = !StringUtils.equals(existing.getCopyResourceUuid(), target.getCopyResourceUuid()) || !StringUtils.equals(existing.description(), target.description()) || !StringUtils.equals(existing.getDbKey(), target.getDbKey()) || !existing.isEnabled() || !StringUtils.equals(existing.getUuidPath(), target.getUuidPath()) || !StringUtils.equals(existing.language(), target.language()) || !StringUtils.equals(existing.longName(), target.longName()) || !StringUtils.equals(existing.moduleUuid(), target.moduleUuid()) || !StringUtils.equals(existing.moduleUuidPath(), target.moduleUuidPath()) || !StringUtils.equals(existing.name(), target.name()) || !StringUtils.equals(existing.path(), target.path()) || !StringUtils.equals(existing.scope(), target.scope()) || !StringUtils.equals(existing.qualifier(), target.qualifier()); ComponentUpdateDto update = null; if (hasDifferences) { update = ComponentUpdateDto .copyFrom(target) .setBChanged(true); } return ofNullable(update); }
db.components().insertPrivateProject(db.getDefaultOrganization(), "U1"); underTest.update(dbSession, new ComponentUpdateDto() .setUuid("U1") .setBKey("key") .setBCopyComponentUuid("copy") .setBChanged(true) .setBDescription("desc") .setBEnabled(true) .setBUuidPath("uuid_path") .setBLanguage("lang") .setBLongName("longName") .setBModuleUuid("moduleUuid") .setBModuleUuidPath("moduleUuidPath") .setBName("name") .setBPath("path") .setBQualifier("qualifier")); dbSession.commit();
private void updateDb(ComponentDto component) { ComponentUpdateDto updateComponent = ComponentUpdateDto.copyFrom(component); updateComponent.setBChanged(true); dbClient.componentDao().update(dbSession, updateComponent); dbClient.componentDao().applyBChangesForRootComponentUuid(dbSession, component.getRootUuid()); dbSession.commit(); }
/** * Copy the A-fields to B-fields. The field bChanged is kept to false. */ public static ComponentUpdateDto copyFrom(ComponentDto from) { return new ComponentUpdateDto() .setUuid(from.uuid()) .setBChanged(false) .setBCopyComponentUuid(from.getCopyResourceUuid()) .setBDescription(from.description()) .setBEnabled(from.isEnabled()) .setBUuidPath(from.getUuidPath()) .setBLanguage(from.language()) .setBLongName(from.longName()) .setBModuleUuid(from.moduleUuid()) .setBModuleUuidPath(from.moduleUuidPath()) .setBName(from.name()) .setBPath(from.path()) .setBQualifier(from.qualifier()); } }
private static Optional<ComponentUpdateDto> compareForUpdate(ComponentDto existing, ComponentDto target) { boolean hasDifferences = !StringUtils.equals(existing.getCopyResourceUuid(), target.getCopyResourceUuid()) || !StringUtils.equals(existing.description(), target.description()) || !existing.isEnabled() || !StringUtils.equals(existing.getUuidPath(), target.getUuidPath()) || !StringUtils.equals(existing.language(), target.language()) || !StringUtils.equals(existing.longName(), target.longName()) || !StringUtils.equals(existing.moduleUuid(), target.moduleUuid()) || !StringUtils.equals(existing.moduleUuidPath(), target.moduleUuidPath()) || !StringUtils.equals(existing.name(), target.name()) || !StringUtils.equals(existing.path(), target.path()) || !StringUtils.equals(existing.qualifier(), target.qualifier()); ComponentUpdateDto update = null; if (hasDifferences) { update = ComponentUpdateDto .copyFrom(target) .setBChanged(true); } return ofNullable(update); }