this.rulesDao = rulesDao;
}
+ public void renameProfile(int profileId, String newProfileName) {
+ RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "id", profileId);
+ if (profile != null && !profile.getProvided()) {
+ String hql = "UPDATE " + RulesProfile.class.getSimpleName() + " o SET o.parentName=:newName WHERE o.parentName=:oldName";
+ getSession().getEntityManager().createQuery(hql)
+ .setParameter("oldName", profile.getName())
+ .setParameter("newName", newProfileName)
+ .executeUpdate();
+ profile.setName(newProfileName);
+ getSession().save(profile);
+ getSession().commit();
+ }
+ }
+
public void copyProfile(int profileId, String newProfileName) {
RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "id", profileId);
RulesProfile toImport = (RulesProfile) profile.clone();
return getContainer().getComponent(ProfilesConsole.class).getProfileExporter(exporterKey).getMimeType();
}
+ public void renameProfile(int profileId, String newProfileName) {
+ getProfilesManager().renameProfile(profileId, newProfileName);
+ }
+
public void copyProfile(long profileId, String newProfileName) {
getProfilesManager().copyProfile((int) profileId, newProfileName);
}
if existing
flash[:warning]='This profile name already exists.'
elsif !profile.provided?
- profile.name=name
- profile.save
+ java_facade.renameProfile(profile.id, name)
end
end
redirect_to :action => 'index'
checkTables("shouldNotDeleteInheritedProfile", "rules_profiles");
}
+ @Test
+ public void shouldRenameInheritedProfile() {
+ setupData("shouldCheckCycles");
+ profilesManager.renameProfile(1, "newName");
+ checkTables("shouldRenameInheritedProfile", "rules_profiles");
+ }
+
@Test
public void shouldSetParent() {
setupData("shouldSetParent");
--- /dev/null
+<dataset>
+
+ <rules id="1" name="foo" description="test" plugin_config_key="checker/foo"
+ plugin_rule_key="checkstyle.rule1" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
+
+ <rules_profiles id="1" provided="false" name="newName" default_profile="0" language="java" parent_name="[null]"/>
+
+ <rules_profiles id="2" provided="false" name="level2" default_profile="0" language="java" parent_name="newName"/>
+
+ <rules_profiles id="3" provided="false" name="level3" default_profile="0" language="java" parent_name="level2"/>
+
+</dataset>