@Test public void testGetLicenseText_5args() throws SQLException, AuthorizeException { Locale locale = null; Collection collection = null; Item item = null; EPerson person = null; Map<String, Object> additionalInfo = null; String template = "Template license: %1$s %2$s %3$s %5$s %6$s"; String templateLong = "Template license: %1$s %2$s %3$s %5$s %6$s %8$s %9$s %10$s %11$s"; String templateResult = "Template license: first name last name test@email.com "; String templateLongResult = "Template license: first name last name test@email.com arg1 arg2 arg3 arg4"; String defaultLicense = ConfigurationManager.getDefaultSubmissionLicense(); context.turnOffAuthorisationSystem(); locale = Locale.ENGLISH; collection = Collection.create(context); item = Item.create(context); person = EPerson.create(context); person.setFirstName("first name"); person.setLastName("last name"); person.setEmail("test@email.com"); additionalInfo = null; assertThat("testGetLicenseText_5args 0", LicenseUtils.getLicenseText(locale, collection, item, person, additionalInfo), equalTo(defaultLicense)); locale = Locale.GERMAN; collection = Collection.create(context); item = Item.create(context); person = EPerson.create(context); person.setFirstName("first name"); person.setLastName("last name"); person.setEmail("test@email.com"); additionalInfo = null; assertThat("testGetLicenseText_5args 1", LicenseUtils.getLicenseText(locale, collection, item, person, additionalInfo), equalTo(defaultLicense)); locale = Locale.ENGLISH; collection = Collection.create(context); item = Item.create(context); person = EPerson.create(context); person.setFirstName("first name"); person.setLastName("last name"); person.setEmail("test@email.com"); additionalInfo = new HashMap<String, Object>(); additionalInfo.put("arg1", "arg1"); additionalInfo.put("arg2", "arg2"); additionalInfo.put("arg3", "arg3"); assertThat("testGetLicenseText_5args 2", LicenseUtils.getLicenseText(locale, collection, item, person, additionalInfo), equalTo(defaultLicense)); locale = Locale.ENGLISH; collection = Collection.create(context); collection.setLicense(template); item = Item.create(context); person = EPerson.create(context); person.setFirstName("first name"); person.setLastName("last name"); person.setEmail("test@email.com"); additionalInfo = null; assertThat("testGetLicenseText_5args 3", LicenseUtils.getLicenseText(locale, collection, item, person, additionalInfo), equalTo(templateResult)); locale = Locale.GERMAN; collection = Collection.create(context); collection.setLicense(template); item = Item.create(context); person = EPerson.create(context); person.setFirstName("first name"); person.setLastName("last name"); person.setEmail("test@email.com"); additionalInfo = null; assertThat("testGetLicenseText_5args 4", LicenseUtils.getLicenseText(locale, collection, item, person, additionalInfo), equalTo(templateResult)); locale = Locale.ENGLISH; collection = Collection.create(context); collection.setLicense(templateLong); item = Item.create(context); person = EPerson.create(context); person.setFirstName("first name"); person.setLastName("last name"); person.setEmail("test@email.com"); additionalInfo = new LinkedHashMap<String, Object>(); additionalInfo.put("arg1", "arg1"); additionalInfo.put("arg2", "arg2"); additionalInfo.put("arg3", "arg3"); additionalInfo.put("arg4", "arg4"); assertThat("testGetLicenseText_5args 5", LicenseUtils.getLicenseText(locale, collection, item, person, additionalInfo), equalTo(templateLongResult)); context.restoreAuthSystemState(); }
public static String getLicenseText(Locale locale, Collection collection, Item item, EPerson eperson, Map<String, Object> additionalInfo) { Formatter formatter = new Formatter(locale); int numArgs = 7 + (additionalInfo != null ? additionalInfo.size() : 0); Object[] args = new Object[numArgs]; args[0] = eperson.getFirstName(); args[1] = eperson.getLastName(); args[2] = eperson.getEmail(); args[3] = new java.util.Date(); args[4] = new FormattableArgument("collection", collection); args[5] = new FormattableArgument("item", item); args[6] = new FormattableArgument("eperson", eperson); if (additionalInfo != null) { int i = 7; for (Map.Entry<String, Object> info : additionalInfo.entrySet()) { args[i] = new FormattableArgument(info.getKey(), info.getValue()); i++; } } String licenseTemplate = collection.getLicense(); return formatter.format(licenseTemplate, args).toString(); }
LicenseUtils { public static String getLicenseText(Locale locale, Collection collection, Item item, EPerson eperson, Map<String, Object> additionalInfo) { Formatter formatter = new Formatter(locale); int numArgs = 7 + (additionalInfo != null ? additionalInfo.size() : 0); Object[] args = new Object[numArgs]; args[0] = eperson.getFirstName(); args[1] = eperson.getLastName(); args[2] = eperson.getEmail(); args[3] = new java.util.Date(); args[4] = new FormattableArgument("collection", collection); args[5] = new FormattableArgument("item", item); args[6] = new FormattableArgument("eperson", eperson); if (additionalInfo != null) { int i = 7; for (Map.Entry<String, Object> info : additionalInfo.entrySet()) { args[i] = new FormattableArgument(info.getKey(), info.getValue()); i++; } } String licenseTemplate = collection.getLicense(); return formatter.format(licenseTemplate, args).toString(); } }
LicenseUtils { public static String getLicenseText(Locale locale, Collection collection, Item item, EPerson eperson, Map<String, Object> additionalInfo) { Formatter formatter = new Formatter(locale); int numArgs = 7 + (additionalInfo != null ? additionalInfo.size() : 0); Object[] args = new Object[numArgs]; args[0] = eperson.getFirstName(); args[1] = eperson.getLastName(); args[2] = eperson.getEmail(); args[3] = new java.util.Date(); args[4] = new FormattableArgument("collection", collection); args[5] = new FormattableArgument("item", item); args[6] = new FormattableArgument("eperson", eperson); if (additionalInfo != null) { int i = 7; for (Map.Entry<String, Object> info : additionalInfo.entrySet()) { args[i] = new FormattableArgument(info.getKey(), info.getValue()); i++; } } String licenseTemplate = collection.getLicense(); return formatter.format(licenseTemplate, args).toString(); }  }
LicenseUtils { public static String getLicenseText(Locale locale, Collection collection, Item item, EPerson eperson, Map<String, Object> additionalInfo) { Formatter formatter = new Formatter(locale); int numArgs = 7 + (additionalInfo != null ? additionalInfo.size() : 0); Object[] args = new Object[numArgs]; args[0] = eperson.getFirstName(); args[1] = eperson.getLastName(); args[2] = eperson.getEmail(); args[3] = new java.util.Date(); args[4] = new FormattableArgument("collection", collection); args[5] = new FormattableArgument("item", item); args[6] = new FormattableArgument("eperson", eperson); if (additionalInfo != null) { int i = 7; for (Map.Entry<String, Object> info : additionalInfo.entrySet()) { args[i] = new FormattableArgument(info.getKey(), info.getValue()); i++; } } String licenseTemplate = collection.getLicense(); return formatter.format(licenseTemplate, args).toString(); }  static String getLicenseText(Locale locale, Collection collection,
            Item item, EPerson eperson, Map<String, Object> additionalInfo); static String getLicenseText(Locale locale, Collection collection,
            Item item, EPerson eperson); static void grantLicense(Context context, Item item,
            String licenseText); }
LicenseUtils { public static String getLicenseText(Locale locale, Collection collection, Item item, EPerson eperson, Map<String, Object> additionalInfo) { Formatter formatter = new Formatter(locale); int numArgs = 7 + (additionalInfo != null ? additionalInfo.size() : 0); Object[] args = new Object[numArgs]; args[0] = eperson.getFirstName(); args[1] = eperson.getLastName(); args[2] = eperson.getEmail(); args[3] = new java.util.Date(); args[4] = new FormattableArgument("collection", collection); args[5] = new FormattableArgument("item", item); args[6] = new FormattableArgument("eperson", eperson); if (additionalInfo != null) { int i = 7; for (Map.Entry<String, Object> info : additionalInfo.entrySet()) { args[i] = new FormattableArgument(info.getKey(), info.getValue()); i++; } } String licenseTemplate = collection.getLicense(); return formatter.format(licenseTemplate, args).toString(); }  static String getLicenseText(Locale locale, Collection collection,
            Item item, EPerson eperson, Map<String, Object> additionalInfo); static String getLicenseText(Locale locale, Collection collection,
            Item item, EPerson eperson); static void grantLicense(Context context, Item item,
            String licenseText);  }