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
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5b25410
[story/VSPC-213]added exhibitionlanguage codes
May 12, 2022
c3f1f8b
[story/VSPC-213] added configuration for language codes and labels
May 18, 2022
c770d63
[story/VSPC-213] added support for multiple exhibition languages
May 23, 2022
959b957
[story/VSPC-213] added test cases
May 23, 2022
bf91424
[story/VSPC-213] added code for default language
May 23, 2022
cbf9519
[VSPC-213] refactor
May 23, 2022
f3285d4
[story/VSPC-213] codefactor
May 23, 2022
7ac5aed
[story/VSPC-213] refactor
May 23, 2022
ff7a491
[story/VSPC-213] revert unwanted file changes
May 23, 2022
1e883bd
[story/VSPC-213] review comments
May 26, 2022
e313921
[story/VSPC-213] modified prefix of exhibition language
May 26, 2022
52e2fd5
[story/VSPC-213] added exceptions. modified exhibition language config
Jun 6, 2022
4575ca4
[story/VSPC-213] added check for only one default language per exhibi…
Jun 7, 2022
f57fa0a
[story/VSPC-213] code factor
Jun 7, 2022
7a8e502
[story/VSPC-213] code factor
Jun 7, 2022
0784a7b
[story/VSPC-213] refactor
Jun 7, 2022
5382226
[story/VSPC-213] refactor
Jun 7, 2022
00cc39f
[story/VSPC-213] added interface for Exhibition language
Jun 10, 2022
98a3eb8
[story/VSPC-213] code factor
Jun 10, 2022
07f65c6
[story/VSPC-213] Merged develop into story/VSPC-213
Jun 16, 2022
00d8754
[story/VSPC-213] langauge list config not found added to exception ha…
Jun 16, 2022
1c566b7
[story/VSPC-213] refactor
Jun 16, 2022
39b9f8b
[story/VSPC-213] modified language list config not found exception
Jun 17, 2022
bcd81b6
[story/VSPC-213] refactor
Jun 17, 2022
72f033b
[story/VSPC-213] review comments
Jun 20, 2022
dcac0ab
[story/VSPC-213] removed LanguageListConfigException declaration
Jun 21, 2022
33712c2
[story/VSPC-213] refactor
Jun 21, 2022
550a4ee
[story/VSPC-213] remove exhibitionlanguage if unselected
Jun 27, 2022
4cea3c2
[story/VSPC-213] added test case
Jun 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[story/VSPC-213] added exceptions. modified exhibition language config
Prachi Kharge authored and Prachi Kharge committed Jun 6, 2022
commit 52e2fd54e3e6b188b3cc9483ba78d375bf1ab923
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
import org.springframework.stereotype.Component;

import edu.asu.diging.vspace.core.model.impl.ExhibitionLanguage;
import org.springframework.core.env.MutablePropertySources;


@Component
@PropertySource(value= "classpath:exhibitionLanguages.properties" , factory=JsonPropertySourceFactory.class)
@@ -37,16 +39,13 @@ public class ExhibitionLanguageConfig {
*/
@PostConstruct
public void init() {
for(Iterator it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext(); ) {
org.springframework.core.env.PropertySource propertySource = (org.springframework.core.env.PropertySource) it.next();
if (propertySource instanceof MapPropertySource) {
MapPropertySource mapSource = ((MapPropertySource) propertySource);
if(ConfigConstants.EXHIBITION_LANGUAGE_LIST_PROPERTY.equals(mapSource.getName())) {
Map<String, Object> languageMap = mapSource.getSource();
exhibitionLanguageList = (List<Map>) languageMap.get(ConfigConstants.LANGUAGES);
}
}

org.springframework.core.env.PropertySource<?> source = ((AbstractEnvironment) environment).getPropertySources().get(ConfigConstants.EXHIBITION_LANGUAGE_LIST_PROPERTY);
if(source !=null ) {
Map<String, Object> languageMap = (Map<String, Object>) source.getSource();
exhibitionLanguageList = (List<Map>) languageMap.get(ConfigConstants.LANGUAGES);
}

}

public List<Map> getExhibitionLanguageList() {
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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



/**
*
*/
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

private static final long serialVersionUID = 1L;

public LanguageListConfigurationNotFound() {
super();
// TODO Auto-generated constructor stub
}

public LanguageListConfigurationNotFound(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
super(arg0, arg1, arg2, arg3);
// TODO Auto-generated constructor stub
}

public LanguageListConfigurationNotFound(String arg0, Throwable arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}

public LanguageListConfigurationNotFound(String arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}

public LanguageListConfigurationNotFound(Throwable arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}

}
Original file line number Diff line number Diff line change
@@ -38,23 +38,15 @@ public ExhibitionLanguage(String label, String code, Exhibition exhibition) {
this.code=code;
this.exhibition=exhibition;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}


public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public Exhibition getExhibition() {
return exhibition;
}
@@ -63,7 +55,22 @@ public void setExhibition(Exhibition exhibition) {
this.exhibition = exhibition;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public boolean isDefault() {
return isDefault;
}

public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}

@Override
public int hashCode() {
return Objects.hash(code, exhibition, label);
@@ -82,12 +89,4 @@ public boolean equals(Object obj) {
&& Objects.equals(label, other.label);
}

public boolean isDefault() {
return isDefault;
}

public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}

}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import java.util.List;

import edu.asu.diging.vspace.core.exception.LanguageListConfigurationNotFound;
import edu.asu.diging.vspace.core.model.IExhibition;
import edu.asu.diging.vspace.core.model.impl.Exhibition;

@@ -34,6 +35,6 @@ public interface IExhibitionManager {

IExhibition getStartExhibition();

void updateExhibitionLanguages(Exhibition exhibition, List<String> languages, String defaultLanguage);
void updateExhibitionLanguages(Exhibition exhibition, List<String> languages, String defaultLanguage) throws LanguageListConfigurationNotFound;

}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import edu.asu.diging.vspace.config.ConfigConstants;
import edu.asu.diging.vspace.config.ExhibitionLanguageConfig;
import edu.asu.diging.vspace.core.data.ExhibitionRepository;
import edu.asu.diging.vspace.core.exception.LanguageListConfigurationNotFound;
import edu.asu.diging.vspace.core.model.IExhibition;
import edu.asu.diging.vspace.core.model.impl.Exhibition;
import edu.asu.diging.vspace.core.model.impl.ExhibitionLanguage;
@@ -86,32 +87,47 @@ public IExhibition getStartExhibition() {
* @param exhibition
* @param defaultLanguage
* @param languages
* @throws LanguageListConfigurationNotFound
*/
@Override
public void updateExhibitionLanguages(Exhibition exhibition, List<String> codes, String defaultLanguage) {
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.

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(defaultLanguage!=null) {
if(defaultLanguage!=null && !codes.contains(defaultLanguage)) {
codes.add(defaultLanguage);
}
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.

List<ExhibitionLanguage> exhibitionLanguages = exhibitionLanguageConfig.getExhibitionLanguageList()
.stream().filter(languageMap -> codes.contains(languageMap.get(ConfigConstants.CODE)))
.map(map -> {
ExhibitionLanguage exhibitionLanguage = new ExhibitionLanguage((String) map.get(ConfigConstants.LABEL),
(String) map.get(ConfigConstants.CODE), exhibition);
.stream().filter(languageConfig -> codes.contains(languageConfig.get(ConfigConstants.CODE)))
.map(languageMap -> {
ExhibitionLanguage exhibitionLanguage = new ExhibitionLanguage((String) languageMap.get(ConfigConstants.LABEL),
(String) languageMap.get(ConfigConstants.CODE), exhibition);

if(exhibitionLanguage.getCode().equalsIgnoreCase(defaultLanguage)) {
exhibitionLanguage.setDefault(true);
} else {
exhibitionLanguage.setDefault(false);
}
return exhibitionLanguage;
}).collect(Collectors.toList());

if(CollectionUtils.isNotEmpty(exhibitionLanguages)) {
logger.info("Updating Exhibition with Languages" + codes);
logger.trace("Updating Exhibition with Languages" + codes);
exhibition.getLanguages().addAll(exhibitionLanguages);
}

// List<ExhibitionLanguage> defaultLanguages= exhibition.getLanguages().stream()
// .filter(language -> language.isDefault() && !language.getCode().equals(defaultLanguage) )
// .map(languageMap -> {languageMap.setDefault(false); return languageMap ; })
//
// .collect(Collectors.toList());
//
// exhibition.getLanguages().removeAll(defaultLanguages);
// exhibition.getLanguages().addAll(defaultLanguages);


}

} else {
logger.error("Language list configuration not available");
throw new LanguageListConfigurationNotFound("Exhibition Language Configuration not found");
}
}

Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@

import edu.asu.diging.vspace.config.ExhibitionLanguageConfig;
import edu.asu.diging.vspace.core.data.SpaceRepository;
import edu.asu.diging.vspace.core.exception.LanguageListConfigurationNotFound;
import edu.asu.diging.vspace.core.factory.impl.ExhibitionFactory;
import edu.asu.diging.vspace.core.model.ExhibitionModes;
import edu.asu.diging.vspace.core.model.IExhibition;
@@ -59,6 +60,9 @@ public String showExhibitions(Model model) {
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.

model.addAttribute("defaultLanguage",exhibition.getLanguages().stream()
.filter(language -> language.isDefault()).findFirst().orElse(null) );

}
} else {
model.addAttribute("exhibition", new Exhibition());
@@ -77,6 +81,7 @@ public String showExhibitions(Model model) {
* @param spaceParam
* @param attributes
* @return
* @throws LanguageListConfigurationNotFound
*/
@RequestMapping(value = "/staff/exhibit/config", method = RequestMethod.POST)
public RedirectView createOrUpdateExhibition(HttpServletRequest request,
@@ -86,7 +91,7 @@ public RedirectView createOrUpdateExhibition(HttpServletRequest request,
@RequestParam(value = "customMessage", required = false, defaultValue = "") String customMessage,
@RequestParam("exhibitLanguage") List<String> languages,
@RequestParam("defaultExhibitLanguage") String defaultLanguage,
RedirectAttributes attributes) throws IOException {
RedirectAttributes attributes) throws IOException, LanguageListConfigurationNotFound {

ISpace startSpace = spaceManager.getSpace(spaceID);

@@ -100,7 +105,7 @@ public RedirectView createOrUpdateExhibition(HttpServletRequest request,
exhibition.setTitle(title);
exhibition.setMode(exhibitMode);
exhibitManager.updateExhibitionLanguages(exhibition,languages,defaultLanguage);

if(exhibitMode.equals(ExhibitionModes.OFFLINE) && !customMessage.equals(ExhibitionModes.OFFLINE.getValue())) {
exhibition.setCustomMessage(customMessage);
}
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ <h2>Exhibition Configuration</h2>
<div style="padding-top: 20px;">
<label for="title">Default Exhibition Language:</label>
<select class="form-control" name="defaultExhibitLanguage" >
<option th:each="language: ${languageList}" th:id=${language.code} th:value=${language.code} th:selected="${mappedLanguages!=null && mappedLanguages.contains(language.label)}">[[${language.label}]]</option>
<option th:each="language: ${languageList}" th:id=${language.code} th:value=${language.code} th:selected="${defaultLanguage!=null && #strings.equals(defaultLanguage.label, language.label)}">[[${language.label}]]</option>
</select>
</div>
<div id="offlineMessage" style="padding-top: 20px;" th:style="${exhibition.mode != 'OFFLINE' ? 'display: none;' : '' }">
Loading