-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Story/vspc 213 #302
Story/vspc 213 #302
Conversation
Can one of the admins verify this patch? |
@Autowired | ||
private Environment environment; | ||
|
||
List<Map> exhibitionLanguageList = new ArrayList<Map>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoudl be private
*/ | ||
@PostConstruct | ||
public void init() { | ||
for(Iterator it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext(); ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since only one is listed in the PropertySource
, can there be more in the list than just this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't get you. There are multiple property sources. we are iterating through it to search for the particular property we need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there more than the one listed in the @PropertySource
annoation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there are around 10 in the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.springframework.core.env.PropertySource propertySource = (org.springframework.core.env.PropertySource) it.next(); | ||
if (propertySource instanceof MapPropertySource) { | ||
MapPropertySource mapSource = ((MapPropertySource) propertySource); | ||
if("json-property".equals(mapSource.getName())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings should never be hard-coded. If a string is needed here, it should be in a constant.
|
||
public ExhibitionLanguage() { | ||
super(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this constructor necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Actually there is a parameterized constructor added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, I didn't see it because constructors should be grouped together after the field declarations ;)
|
||
@Id | ||
@GeneratedValue(generator = "exhibit_language_id_generator") | ||
@GenericGenerator(name = "exhibit_language_id_generator", parameters = @Parameter(name = "prefix", value = "EXH"), strategy = "edu.asu.diging.vspace.core.data.IdGenerator") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXH
is the prefix for exhibitiion objects. here it should be a prefix for language objects.
@Autowired | ||
private ExhibitionLanguageConfig exhibitionLanguageConfig; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llogger decllarations should be first in the class
.stream().filter(map-> code.equalsIgnoreCase((String) map.get("code"))) | ||
.map(language -> { | ||
ExhibitionLanguage exhibitionLanguage = new ExhibitionLanguage((String) language.get("label"), | ||
(String) language.get("code"), exhibition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before, hard-coded strings should be in constants
if(defaultLanguage!=null) { | ||
codes.add(defaultLanguage); | ||
} | ||
codes.forEach(code -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would turn this around and iterate over exhibitionLanguageConfig.getExhibitionLanguageList(). You would only need one stream and filter for everything in the codes list. So only one iteration instead of multiple if I'm not mistaken.
*/ | ||
@PostConstruct | ||
public void init() { | ||
for(Iterator it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext(); ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
public void setDefault(boolean isDefault) { | ||
this.isDefault = isDefault; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getter and setters should be in order of variable declaration. hashcode/equals should be after getters/setters.
if(CollectionUtils.isNotEmpty(exhibitionLanguageConfig.getExhibitionLanguageList())) { | ||
List<ExhibitionLanguage> exhibitionLanguages = exhibitionLanguageConfig.getExhibitionLanguageList() | ||
.stream().filter(languageMap -> codes.contains(languageMap.get(ConfigConstants.CODE))) | ||
.map(map -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
(as variable name) is a language, isn't it? It should have a. better name.
@Override | ||
public void updateExhibitionLanguages(Exhibition exhibition, List<String> codes, String defaultLanguage) { | ||
if(CollectionUtils.isNotEmpty(codes)) { | ||
if(defaultLanguage!=null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& !codes.contains(defaultLanguage)
or you might end up with the same code twice?
}).collect(Collectors.toList()); | ||
|
||
if(CollectionUtils.isNotEmpty(exhibitionLanguages)) { | ||
logger.info("Updating Exhibition with Languages" + codes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove; it doesn't add any value. If at all, this should be trace.
exhibition.getLanguages().addAll(exhibitionLanguages); | ||
} | ||
} else { | ||
logger.error("Language list configuration not available"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case we probably want to throw an exception since that would indicate a faulty installation.
|
||
@RequestMapping("/staff/exhibit/config") | ||
public String showExhibitions(Model model) { | ||
// for now we assume there is just one exhibition | ||
IExhibition exhibition = exhibitManager.getStartExhibition(); | ||
if(exhibition!=null) { | ||
model.addAttribute("exhibition", exhibition); | ||
if(exhibition.getLanguages() != null ) { | ||
model.addAttribute("mappedLanguages", exhibition.getLanguages() | ||
.stream().map(language -> language.getLabel()).collect(Collectors.toList())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are "mappedLanguages"? and why not putting the language list in the model (not just the labels), you probably need them somewhere (or if not, it's just a .label
more to show the language names).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mappedLanguages is just used to highlight the already mapped languages to an exhibition, in the selection dropdown. This is to avoid adding any more logic in front end.
The entire language object is being sent to populate the dropdown in "languageList".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, makes sense. It needs a better name though. It's not clear what "mappedLanguages" would be in this context.
import edu.asu.diging.vspace.core.model.impl.Exhibition; | ||
import edu.asu.diging.vspace.core.model.impl.ExhibitionLanguage; | ||
|
||
public class ExhibitionLanguageTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests class should be named ClassToBeTestedNameTest
|
||
/** | ||
* | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless you intend to add javadoc here, remove
import org.hibernate.annotations.Parameter; | ||
|
||
@Entity | ||
public class ExhibitionLanguage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface is missing
*/ | ||
@Override | ||
public void updateExhibitionLanguages(Exhibition exhibition, List<String> codes, String defaultLanguage) throws LanguageListConfigurationNotFound { | ||
if(CollectionUtils.isNotEmpty(codes)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you turn the if condition around (if codes is empty) you can avoid such a big if block by returning right away.
} | ||
|
||
|
||
if(CollectionUtils.isNotEmpty(exhibitionLanguageConfig.getExhibitionLanguageList())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check this right at the beginning. no need to do anything if there is no exhibition language list.
(String) languageMap.get(ConfigConstants.CODE), exhibition); | ||
|
||
int index = exhibition.getLanguages().indexOf(exhibitionLanguage); | ||
if( index < 0 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use exhibition.getLanguages().contains()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would need the object to update isDefault to false in case a different default language is selected by user. Hence using index.
if( index < 0 ) { | ||
exhibition.getLanguages().add(exhibitionLanguage); | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please follow our style guide
vspace/src/main/java/edu/asu/diging/vspace/core/services/impl/ExhibitionManager.java
Show resolved
Hide resolved
|
||
@RequestMapping("/staff/exhibit/config") | ||
public String showExhibitions(Model model) { | ||
// for now we assume there is just one exhibition | ||
IExhibition exhibition = exhibitManager.getStartExhibition(); | ||
if(exhibition!=null) { | ||
model.addAttribute("exhibition", exhibition); | ||
if(exhibition.getLanguages() != null ) { | ||
model.addAttribute("mappedLanguages", exhibition.getLanguages() | ||
.stream().map(language -> language.getLabel()).collect(Collectors.toList())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, makes sense. It needs a better name though. It's not clear what "mappedLanguages" would be in this context.
if (getClass() != obj.getClass()) | ||
return false; | ||
Exhibition other = (Exhibition) obj; | ||
return Objects.equals(id, other.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge with line 154
@Override | ||
public void updateExhibitionLanguages(Exhibition exhibition, List<String> codes, String defaultLanguage) throws LanguageListConfigurationNotFound { | ||
if(CollectionUtils.isEmpty(exhibitionLanguageConfig.getExhibitionLanguageList())) { | ||
throw new LanguageListConfigurationNotFound("Exhibition Language Configuration not found"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would make LanguageListConfigurationNotFound
a RuntimeException. If this happens it means that the installation is incomplete or something else is going wrong and there is really no good way out. So I'd make it a runtime exception and not declare or handle the exception. Then just add a handler to the ExhibitionExceptionHandler
that handles all runtime exceptions by showing a 500 page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added it to the exception handler. The exception is thrown and not being handled. Is there any thing else to be done for this?
modelAndView.addObject("showAlert", true); | ||
modelAndView.addObject("message", ex.getMessage()); | ||
logger.info("LanguageListConfigurationNotFound Occured:: URL=" + request.getRequestURL()); | ||
logger.info("Code:: "+language_list_configuration_not_found+" Message:: " + ex.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you want to make sure to log the stacktrace
* @throws LanguageListConfigurationNotFound | ||
*/ | ||
@Override | ||
public void updateExhibitionLanguages(Exhibition exhibition, List<String> codes, String defaultLanguage) throws LanguageListConfigurationNotFound { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the exception should be a runtime exception and wouldn't need to be declared.
@@ -0,0 +1,27 @@ | |||
package edu.asu.diging.vspace.core.exception; | |||
|
|||
public class LanguageListConfigurationNotFound extends Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a runtime exception and exception class names should end in Exception
Make it so, Jenkins. |
Besides that, looks good. |
if (getClass() != obj.getClass()) | ||
return false; | ||
return Objects.equals(id, ((Exhibition) obj).id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I didn't see this before but first all getters/setters then hashcode/equals methods.
modelAndView.addObject("showAlert", true); | ||
modelAndView.addObject("message", ex.getMessage()); | ||
logger.info("LanguageListConfigurationNotFound Occured:: URL=" + request.getRequestURL()); | ||
logger.info("Code:: "+language_list_configuration_not_found+" Cause:: " + ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should be logged as error
RedirectAttributes attributes) throws IOException { | ||
@RequestParam("exhibitLanguage") List<String> languages, | ||
@RequestParam("defaultExhibitLanguage") String defaultLanguage, | ||
RedirectAttributes attributes) throws IOException, LanguageListConfigurationNotFoundException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runtime exceptions don't need to be declared
@@ -59,13 +82,16 @@ public String showExhibitions(Model model) { | |||
* @param spaceParam | |||
* @param attributes | |||
* @return | |||
* @throws LanguageListConfigurationNotFoundException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method is not throwing this anymore
Make it so, Jenkins. |
After that should be good. |
Make it so, Jenkins. |
There seems to be a bug. I have 4 languages currently selected, I've deselected 2 and saved. But the four are still selected when the page reloads. |
Make it so, Jenkins. |
Guidelines for Pull Requests
If you haven't yet read our code review guidelines, please do so, You can find them here.
Please confirm the following by adding an x for each item (turn
[ ]
into[x]
).Please provide a brief description of your ticket
(you can copy the ticket if it hasn't changed)
In the exhibition configuration, users should be able to specify multiple languages for the exhibition. This ticket is just for the specification of languages, not providing text for multiple languages. So, all this needs to be doing is letting the user select languages from a list of languages. There needs to be a default language as well. So the user would select one of the languages as default language.
The follow up tickets will deal with adding slide and space texts in multiple languages. So the data model for this ticket should be a new Language or ExhibitionLanguage class which at the moment won’t have much additional info besides a label and a 2 character ISO code (e.g. en, de, it,…).
Anything else the reviewer needs to know?
... describe here ...