public ProfileImporter getProfileImporter(String exporterKey) { for (ProfileImporter importer : importers) { if (StringUtils.equals(exporterKey, importer.getKey())) { return importer; } } return null; }
public List<ProfileImporter> getProfileImportersForLanguage(String language) { List<ProfileImporter> result = new ArrayList<ProfileImporter>(); for (ProfileImporter importer : importers) { if (importer.getSupportedLanguages() == null || importer.getSupportedLanguages().length == 0 || ArrayUtils.contains(importer.getSupportedLanguages(), language)) { result.add(importer); } } return result; }
/** Important : the ruby controller has already create the profile */ public ValidationMessages importProfile( String profileName, String language, String importerKey, String profileDefinition) { ValidationMessages messages = ValidationMessages.create(); ProfileImporter importer = getProfileImporter(importerKey); RulesProfile profile = importer.importProfile(new StringReader(profileDefinition), messages); if (!messages.hasErrors()) { DatabaseSession session = sessionFactory.getSession(); RulesProfile persistedProfile = session.getSingleResult(RulesProfile.class, "name", profileName, "language", language); for (ActiveRule activeRule : profile.getActiveRules()) { ActiveRule persistedActiveRule = persistedProfile.activateRule(activeRule.getRule(), activeRule.getSeverity()); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { persistedActiveRule.setParameter(activeRuleParam.getKey(), activeRuleParam.getValue()); } } session.saveWithoutFlush(persistedProfile); session.commit(); } return messages; }
@Test public void canAcceptObjectArrayOfStrings() throws IOException, RepositoryException { Object[] objectArrayWithStrings = new Object[] {"{topprop: topvalue}"}; parameters.put(PersonalConstants.PROFILE_JSON_IMPORT_PARAMETER, objectArrayWithStrings); ProfileImporter.importFromParameters(profileNode, parameters, contentImporter, session, null); verify(contentImporter) .importContent( eq(profileNode), eq(ProfileImporter.CONTENT_ROOT_NAME), any(InputStream.class), any(ImportOptions.class), any(ContentImportListener.class)); }