Skip to content
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

Merged
merged 29 commits into from
Jun 28, 2022
Merged

Story/vspc 213 #302

merged 29 commits into from
Jun 28, 2022

Conversation

pkharge
Copy link
Contributor

@pkharge pkharge commented May 23, 2022

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]).

  • I have removed all code style changes that are not necessary (e.g. changing blanks across the whole file that don’t need to be changed, adding empty lines in parts other than your own code)
  • I am not making any changes to files that don’t have any effect (e.g. imports added that don’t need to be added)
  • I do not have any sysout statements in my code or commented out code that isn’t needed anymore
  • I am not reformatting any files in the wrong format or without cause.
  • I am not changing file encoding or line endings to something else than UTF-8, LF
  • My pull request does not show an insane amount of files being changed although my ticket only requires a few files being changed
  • I have added Javadoc/documentation where appropriate
  • I have added test cases where appropriate
  • I have explained any part of my code/implementation decisions that is not be self-explanatory

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 ...

@diging-jenkins
Copy link

Can one of the admins verify this patch?

@Autowired
private Environment environment;

List<Map> exhibitionLanguageList = new ArrayList<Map>();
Copy link
Member

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(); ) {
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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())) {
Copy link
Member

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();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this constructor necessary?

Copy link
Contributor Author

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.

Copy link
Member

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")
Copy link
Member

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());
Copy link
Member

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);
Copy link
Member

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 -> {
Copy link
Member

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.

@jdamerow jdamerow closed this May 25, 2022
@pkharge pkharge reopened this May 26, 2022
*/
@PostConstruct
public void init() {
for(Iterator it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext(); ) {
Copy link
Member

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;
}
Copy link
Member

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 -> {
Copy link
Member

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) {
Copy link
Member

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);
Copy link
Member

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");
Copy link
Member

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()));
Copy link
Member

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).

Copy link
Contributor Author

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".

Copy link
Member

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 {
Copy link
Member

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

@jdamerow jdamerow closed this May 27, 2022
@pkharge pkharge reopened this Jun 7, 2022

/**
*
*/
Copy link
Member

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 {
Copy link
Member

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)) {
Copy link
Member

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())) {
Copy link
Member

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 ) {
Copy link
Member

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()?

Copy link
Contributor Author

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 {
Copy link
Member

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


@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()));
Copy link
Member

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.

@jdamerow jdamerow closed this Jun 8, 2022
@pkharge pkharge reopened this Jun 10, 2022
if (getClass() != obj.getClass())
return false;
Exhibition other = (Exhibition) obj;
return Objects.equals(id, other.id);
Copy link
Member

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");
Copy link
Member

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.

Copy link
Contributor Author

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?

@pkharge pkharge reopened this Jun 16, 2022
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());
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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

@jdamerow
Copy link
Member

Make it so, Jenkins.

@jdamerow
Copy link
Member

Besides that, looks good.

@jdamerow jdamerow closed this Jun 17, 2022
@pkharge pkharge reopened this Jun 17, 2022
if (getClass() != obj.getClass())
return false;
return Objects.equals(id, ((Exhibition) obj).id);
}
Copy link
Member

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);
Copy link
Member

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 {
Copy link
Member

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

@jdamerow jdamerow closed this Jun 20, 2022
@pkharge pkharge reopened this Jun 20, 2022
@@ -59,13 +82,16 @@ public String showExhibitions(Model model) {
* @param spaceParam
* @param attributes
* @return
* @throws LanguageListConfigurationNotFoundException
Copy link
Member

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

@jdamerow
Copy link
Member

Make it so, Jenkins.

@jdamerow
Copy link
Member

After that should be good.

@jdamerow jdamerow closed this Jun 21, 2022
@pkharge pkharge reopened this Jun 21, 2022
@jdamerow
Copy link
Member

Make it so, Jenkins.

@jdamerow
Copy link
Member

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.

@jdamerow jdamerow closed this Jun 24, 2022
@pkharge pkharge reopened this Jun 27, 2022
@jdamerow
Copy link
Member

Make it so, Jenkins.

@jdamerow jdamerow merged commit 1181039 into develop Jun 28, 2022
@jdamerow jdamerow deleted the story/VSPC-213 branch June 28, 2022 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants