Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -re952488de6475350bc2fab3272b5350b3a7a6d51 -r1de0a203f1cc55783cffd95742782070877781cb Binary files differ Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== diff -u -r62aaf160878735888d077bf28fac3c1989bb8fbd -r1de0a203f1cc55783cffd95742782070877781cb --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 62aaf160878735888d077bf28fac3c1989bb8fbd) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -27,7 +27,6 @@ import java.io.IOException; import java.text.ParseException; import java.util.ArrayList; -import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -76,7 +75,6 @@ import org.lamsfoundation.lams.learningdesign.dao.ILearningLibraryDAO; import org.lamsfoundation.lams.learningdesign.dao.ILicenseDAO; import org.lamsfoundation.lams.learningdesign.dao.ITransitionDAO; -import org.lamsfoundation.lams.learningdesign.dto.AuthoringActivityDTO; import org.lamsfoundation.lams.learningdesign.dto.ValidationErrorDTO; import org.lamsfoundation.lams.learningdesign.exception.LearningDesignException; import org.lamsfoundation.lams.learningdesign.service.ILearningDesignService; @@ -105,6 +103,7 @@ import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException; import org.lamsfoundation.lams.usermanagement.exception.UserException; import org.lamsfoundation.lams.usermanagement.exception.WorkspaceFolderException; +import org.lamsfoundation.lams.util.AuthoringJsonTags; import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.JsonUtil; @@ -808,7 +807,7 @@ WorkspaceFolder workspaceFolder, boolean setOriginalDesign, String newDesignName, String customCSV) { String newTitle = newDesignName; if (newTitle == null) { - newTitle = getUniqueNameForLearningDesign(originalLearningDesign.getTitle(), + newTitle = learningDesignService.getUniqueNameForLearningDesign(originalLearningDesign.getTitle(), workspaceFolder != null ? workspaceFolder.getWorkspaceFolderId() : null); } @@ -1333,7 +1332,17 @@ throw new UserException("User with ID " + userID + " is not authorized to store a design in this workspace folder " + workspaceFolderID); } - + if (existingLearningDesign == null) { + // check the user has given it a unique name in this folder, and make it unique if needed + String title = JsonUtil.optString(ldJSON, AuthoringJsonTags.TITLE); + if ( title != null ) { + title = learningDesignService.getUniqueNameForLearningDesign(title, workspaceFolderID); + } else { + title = messageService.getMessage("authoring.fla.page.ld.title"); + } + ldJSON.put(AuthoringJsonTags.TITLE, title); + } + IObjectExtractor extractor = (IObjectExtractor) beanFactory .getBean(IObjectExtractor.OBJECT_EXTRACTOR_SPRING_BEANNAME); LearningDesign design = extractor.extractSaveLearningDesign(ldJSON, existingLearningDesign, workspaceFolder, @@ -1412,46 +1421,6 @@ } /** - * Get a unique name for a learning design, based on the names of the learning designs in the folder. If the - * learning design has duplicated name in same folder, then the new name will have a timestamp. The new name format - * will be oldname_ddMMYYYY_idx. The idx will be auto incremental index number, start from 1. Warning - this may be - * quite intensive as it gets all the learning designs in a folder. - * - * @param originalLearningDesign - * @param workspaceFolder - * @param copyType - * @return - */ - @Override - public String getUniqueNameForLearningDesign(String originalTitle, Integer workspaceFolderId) { - - String newName = originalTitle; - if (workspaceFolderId != null) { - List ldTitleList = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(workspaceFolderId, - originalTitle); - int idx = 1; - - Calendar calendar = Calendar.getInstance(); - int mth = calendar.get(Calendar.MONTH) + 1; - String mthStr = new Integer(mth).toString(); - if (mth < 10) { - mthStr = "0" + mthStr; - } - int day = calendar.get(Calendar.DAY_OF_MONTH); - String dayStr = new Integer(day).toString(); - if (day < 10) { - dayStr = "0" + dayStr; - } - String nameMid = dayStr + mthStr + calendar.get(Calendar.YEAR); - while (ldTitleList.contains(newName)) { - newName = originalTitle + "_" + nameMid + "_" + idx; - idx++; - } - } - return newName; - } - - /** * Creates a LD with only one, given activity. If organisation is given, the LD will not be stored in user folder, * but will be put straight into run sequences folder of the organisation. */ Index: lams_central/src/java/org/lamsfoundation/lams/authoring/template/web/LdTemplateController.java =================================================================== diff -u -r10407509921c1b1233270863d7549ce68cc38c5c -r1de0a203f1cc55783cffd95742782070877781cb --- lams_central/src/java/org/lamsfoundation/lams/authoring/template/web/LdTemplateController.java (.../LdTemplateController.java) (revision 10407509921c1b1233270863d7549ce68cc38c5c) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/template/web/LdTemplateController.java (.../LdTemplateController.java) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -296,9 +296,9 @@ } /** - * Create a unique title for this learning design, within the right length for the database. The title will - * be __UniqueDate, where the userEnteredString is capitalised and - * whitespace is removed. + * Create a title for this learning design, within the right length for the database. The userEnteredString is + * capitalised and whitespace is removed. The call to saveLearningDesign will make it unique by appending a date + * if needed. * * @param sequenceTitle * @param workspaceFolderID @@ -307,7 +307,6 @@ private String createTitle(String templateCode, String userEnteredString, Integer workspaceFolderID) { String title = WebUtil.removeHTMLtags(userEnteredString); title = title.replaceAll("[@%<>/^/*/$]", ""); - title = authoringService.getUniqueNameForLearningDesign(title, workspaceFolderID); if (title.length() > 220) { title.substring(0, 220); } Index: lams_central/web/includes/javascript/authoring/authoringGeneral.js =================================================================== diff -u -r7a3f0b4333c6c3aba00560735a50b610f76d1029 -r1de0a203f1cc55783cffd95742782070877781cb --- lams_central/web/includes/javascript/authoring/authoringGeneral.js (.../authoringGeneral.js) (revision 7a3f0b4333c6c3aba00560735a50b610f76d1029) +++ lams_central/web/includes/javascript/authoring/authoringGeneral.js (.../authoringGeneral.js) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -413,7 +413,7 @@ $.ajax({ cache : false, - url : copiedResource.isCut ? 'LAMS_URL + "workspace/moveResource.do' : 'LAMS_URL + "workspace/copyResource.do', + url : copiedResource.isCut ? LAMS_URL + "workspace/moveResource.do" : LAMS_URL + "workspace/copyResource.do", dataType : 'text', data : { 'targetFolderID' : folderNode.data.folderID, Index: lams_common/src/java/org/lamsfoundation/lams/authoring/IAuthoringService.java =================================================================== diff -u -r5caa0c70153ab564c5d8e347c4af4baf53b01fd0 -r1de0a203f1cc55783cffd95742782070877781cb --- lams_common/src/java/org/lamsfoundation/lams/authoring/IAuthoringService.java (.../IAuthoringService.java) (revision 5caa0c70153ab564c5d8e347c4af4baf53b01fd0) +++ lams_common/src/java/org/lamsfoundation/lams/authoring/IAuthoringService.java (.../IAuthoringService.java) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -45,19 +45,6 @@ LearningDesign copyLearningDesign(LearningDesign originalLearningDesign, Integer copyType, User user, WorkspaceFolder workspaceFolder, boolean setOriginalDesign, String newDesignName, String customCSV); - /** - * Get a unique name for a learning design, based on the names of the learning designs in the folder. If the - * learning design has duplicated name in same folder, then the new name will have a timestamp. The new name format - * will be oldname_ddMMYYYY_idx. The idx will be auto incremental index number, start from 1. Warning - this may be - * quite intensive as it gets all the learning designs in a folder. - * - * @param originalLearningDesign - * @param workspaceFolder - * @param copyType - * @return - */ - String getUniqueNameForLearningDesign(String originalTitle, Integer workspaceFolderId); - Grouping getGroupingById(Long groupingID); /** Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml =================================================================== diff -u -r62aaf160878735888d077bf28fac3c1989bb8fbd -r1de0a203f1cc55783cffd95742782070877781cb --- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 62aaf160878735888d077bf28fac3c1989bb8fbd) +++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -239,6 +239,8 @@ + + Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java =================================================================== diff -u -r5b6ae6b7ee8ace9fe2d02d76b5b5763149b07cf6 -r1de0a203f1cc55783cffd95742782070877781cb --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision 5b6ae6b7ee8ace9fe2d02d76b5b5763149b07cf6) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ExportToolContentService.java (.../ExportToolContentService.java) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -39,7 +39,6 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.ArrayList; -import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -160,11 +159,7 @@ public class ExportToolContentService implements IExportToolContentService, ApplicationContextAware { private Logger log = Logger.getLogger(ExportToolContentService.class); - public static final String LEARNING_DESIGN_SERVICE_BEAN_NAME = "learningDesignService"; - - public static final String MESSAGE_SERVICE_BEAN_NAME = "commonMessageService"; - - // export tool content zip file prefix + // export tool content zip file prefix public static final String EXPORT_TOOLCONTNET_ZIP_PREFIX = "lams_toolcontent_"; public static final String EXPORT_LDCONTENT_ZIP_PREFIX = "lams_ldcontent_"; @@ -207,9 +202,11 @@ // message keys private static final String KEY_MSG_IMPORT_FILE_FORMAT = "msg.import.file.format"; - private static MessageService messageService; + private MessageService messageService; + private ILearningDesignService learningDesignService; private ApplicationContext applicationContext; + // save list of all tool file node class information. One tool may have // over one file node, such as @@ -408,8 +405,7 @@ // get learning desing and serialize it to XML file. Update the // version to reflect the version now, rather than the version when it was saved. - ILearningDesignService service = getLearningDesignService(); - LearningDesignDTO ldDto = service.getLearningDesignDTO(learningDesignId, ""); + LearningDesignDTO ldDto = learningDesignService.getLearningDesignDTO(learningDesignId, ""); ldDto.setVersion(Configuration.get(ConfigurationKeys.SERVER_VERSION_NUMBER)); /* @@ -706,7 +702,7 @@ ldDto.setDescription(ldDto.getDescription().replaceAll(oldResourcePath, newResourcePath)); } for (AuthoringActivityDTO activity : activities) { - getLearningDesignService().fillLearningLibraryID(activity, activities); + learningDesignService.fillLearningLibraryID(activity, activities); // skip non-tool activities if (!activity.getActivityTypeID().equals(Activity.TOOL_ACTIVITY_TYPE)) { continue; @@ -722,7 +718,7 @@ // can not find a matching tool if (newTool == null) { log.warn("An activity can not found matching tool [" + activity.getToolSignature() + "]."); - toolsErrorMsgs.add(getMessageService().getMessage(ExportToolContentService.ERROR_TOOL_NOT_FOUND, + toolsErrorMsgs.add(messageService.getMessage(ExportToolContentService.ERROR_TOOL_NOT_FOUND, new Object[] { activity.getToolSignature() })); // remove this activity from LD @@ -771,7 +767,7 @@ } log.debug("Tool content import success."); } catch (Exception e) { - String error = getMessageService().getMessage(ExportToolContentService.ERROR_SERVICE_ERROR, + String error = messageService.getMessage(ExportToolContentService.ERROR_SERVICE_ERROR, new Object[] { newTool.getToolDisplayName(), e.toString() }); log.error(error, e); toolsErrorMsgs.add(error); @@ -783,7 +779,7 @@ // all activities can not imported, ignore this LD if (removedActMap.size() == activities.size()) { - toolsErrorMsgs.add(getMessageService().getMessage(ExportToolContentService.ERROR_NO_VALID_TOOL)); + toolsErrorMsgs.add(messageService.getMessage(ExportToolContentService.ERROR_NO_VALID_TOOL)); return -1L; } @@ -846,13 +842,13 @@ log.warn( "Importing a design from a later version of LAMS. There may be parts of the design that will fail to import. Design name \'" + title + "\'. Version in import file " + versionString); - toolsErrorMsgs.add(getMessageService().getMessage(ExportToolContentService.ERROR_INCOMPATIBLE_VERSION, + toolsErrorMsgs.add(messageService.getMessage(ExportToolContentService.ERROR_INCOMPATIBLE_VERSION, new Object[] { versionString, currentVersionString })); } } catch (Exception e) { log.warn("Unable to properly determine current version from an import file. Design name \'" + title + "\'. Version in import file " + versionString); - toolsErrorMsgs.add(getMessageService().getMessage(ExportToolContentService.ERROR_INCOMPATIBLE_VERSION, + toolsErrorMsgs.add(messageService.getMessage(ExportToolContentService.ERROR_INCOMPATIBLE_VERSION, new Object[] { versionString, currentVersionString })); } @@ -910,8 +906,7 @@ private void badFileType(List ldErrorMsgs, String filename, String errDescription) { log.error("Uploaded file not an expected type. Filename was " + filename + " " + errDescription); - MessageService msgService = getMessageService(); - String msg = msgService.getMessage(ExportToolContentService.KEY_MSG_IMPORT_FILE_FORMAT); + String msg = messageService.getMessage(ExportToolContentService.KEY_MSG_IMPORT_FILE_FORMAT); ldErrorMsgs.add(msg != null ? msg : "Uploaded file not an expected type."); } @@ -1136,20 +1131,6 @@ } } - private ILearningDesignService getLearningDesignService() { - return (ILearningDesignService) applicationContext - .getBean(ExportToolContentService.LEARNING_DESIGN_SERVICE_BEAN_NAME); - } - - private MessageService getMessageService() { - if (ExportToolContentService.messageService != null) { - return ExportToolContentService.messageService; - } - - return ExportToolContentService.messageService = (MessageService) applicationContext - .getBean(ExportToolContentService.MESSAGE_SERVICE_BEAN_NAME); - } - private Object findToolService(Tool tool) throws NoSuchBeanDefinitionException { return applicationContext.getBean(tool.getServiceName()); } @@ -1408,7 +1389,7 @@ competenceList); // validate learning design - Vector listOfValidationErrorDTOs = getLearningDesignService().validateLearningDesign(ld); + Vector listOfValidationErrorDTOs = learningDesignService.validateLearningDesign(ld); if (listOfValidationErrorDTOs.size() > 0) { ld.setValidDesign(false); log.error(listOfValidationErrorDTOs); @@ -1425,7 +1406,10 @@ // add suffix if configuration is not set or is set to true String addSuffix = Configuration.get(ConfigurationKeys.SUFFIX_IMPORTED_LD); if ((addSuffix == null) || Boolean.valueOf(addSuffix)) { - ld.setTitle(ExportToolContentService.generateUniqueLDTitle(folder, ld.getTitle(), learningDesignDAO)); + String title = ld.getTitle(); + if (title == null || title.trim().length() == 0) + title = "unknown"; + ld.setTitle(learningDesignService.getUniqueNameForLearningDesign(ld.getTitle(), folder.getWorkspaceFolderId())); learningDesignDAO.update(ld); // persist } @@ -1949,52 +1933,6 @@ act.setEndYcoord(actDto.getEndYCoord()); } - private static String generateUniqueLDTitle(WorkspaceFolder folder, String titleFromFile, - ILearningDesignDAO learningDesignDAO) { - - String newTitle = titleFromFile; - if ((newTitle == null) || (newTitle.length() == 0)) { - newTitle = "unknown"; - } - - if (folder != null) { - boolean dupName; - List ldList = learningDesignDAO - .getAllLearningDesignsInFolder(folder.getWorkspaceFolderId()); - int idx = 1; - - //contruct middle part of name by timestamp - Calendar calendar = Calendar.getInstance(); - int mth = calendar.get(Calendar.MONTH) + 1; - String mthStr = new Integer(mth).toString(); - if (mth < 10) { - mthStr = "0" + mthStr; - } - int day = calendar.get(Calendar.DAY_OF_MONTH); - String dayStr = new Integer(day).toString(); - if (day < 10) { - dayStr = "0" + dayStr; - } - String nameMid = dayStr + mthStr + calendar.get(Calendar.YEAR); - while (true) { - dupName = false; - for (LearningDesign eld : ldList) { - if (StringUtils.equals(eld.getTitle(), newTitle)) { - dupName = true; - break; - } - } - if (!dupName) { - break; - } - newTitle = titleFromFile + "_" + nameMid + "_" + idx; - idx++; - } - } - - return newTitle; - } - /** * Convert content folder ID to real path inside secure dir or on server */ @@ -2078,4 +2016,20 @@ public void setSystemToolDAO(ISystemToolDAO systemToolDAO) { this.systemToolDAO = systemToolDAO; } + + public MessageService getMessageService() { + return messageService; + } + + public void setMessageService(MessageService messageService) { + this.messageService = messageService; + } + + public ILearningDesignService getLearningDesignService() { + return learningDesignService; + } + + public void setLearningDesignService(ILearningDesignService learningDesignService) { + this.learningDesignService = learningDesignService; + } } \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ILearningDesignService.java =================================================================== diff -u -r671c0123933f9264962a7a2a9aba940ded111d57 -r1de0a203f1cc55783cffd95742782070877781cb --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ILearningDesignService.java (.../ILearningDesignService.java) (revision 671c0123933f9264962a7a2a9aba940ded111d57) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/ILearningDesignService.java (.../ILearningDesignService.java) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -99,4 +99,21 @@ throws ImportToolContentException; String internationaliseActivityTitle(Long learningLibraryID); + + /** + * Get a unique name for a learning design, based on the names of the learning designs in the folder. If the + * learning design has duplicated name in same folder, then the new name will have a timestamp. The new name format + * will be oldname_ddMMYYYY_idx. The idx will be auto incremental index number, start from 1. Warning - this may be + * quite intensive as it gets all the learning designs in a folder. Moved from AuthoringService to here so that the + * Import code can use it. + * + * + * @param originalLearningDesign + * @param workspaceFolder + * @param copyType + * @return + */ + String getUniqueNameForLearningDesign(String originalTitle, Integer workspaceFolderId); + + } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LearningDesignService.java =================================================================== diff -u -r671c0123933f9264962a7a2a9aba940ded111d57 -r1de0a203f1cc55783cffd95742782070877781cb --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LearningDesignService.java (.../LearningDesignService.java) (revision 671c0123933f9264962a7a2a9aba940ded111d57) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/service/LearningDesignService.java (.../LearningDesignService.java) (revision 1de0a203f1cc55783cffd95742782070877781cb) @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -492,4 +493,51 @@ } return FileUtil.getFullPath(thumbnailDir.getAbsolutePath(), thumbnailFileName); } + + /** + * Get a unique name for a learning design, based on the names of the learning designs in the folder. If the + * learning design has duplicated name in same folder, then the new name will have a timestamp. The new name format + * will be oldname_ddMMYYYY_idx. The idx will be auto incremental index number, start from 1. Warning - this may be + * quite intensive as it gets all the learning designs in a folder. Moved from AuthoringService to here so that the + * Import code can use it. + * + * @param originalLearningDesign + * @param workspaceFolder + * @param copyType + * @return + */ + @Override + public String getUniqueNameForLearningDesign(String originalTitle, Integer workspaceFolderId) { + + String newName = originalTitle; + if (workspaceFolderId != null) { + List ldTitleList = learningDesignDAO.getLearningDesignTitlesByWorkspaceFolder(workspaceFolderId, + originalTitle); + + if ( ldTitleList.size() == 0 ) { + return originalTitle; + } + + Calendar calendar = Calendar.getInstance(); + int mth = calendar.get(Calendar.MONTH) + 1; + String mthStr = new Integer(mth).toString(); + if (mth < 10) { + mthStr = "0" + mthStr; + } + int day = calendar.get(Calendar.DAY_OF_MONTH); + String dayStr = new Integer(day).toString(); + if (day < 10) { + dayStr = "0" + dayStr; + } + String nameMid = dayStr + mthStr + calendar.get(Calendar.YEAR); + + int idx = 1; + while (ldTitleList.contains(newName)) { + newName = originalTitle + "_" + nameMid + "_" + idx; + idx++; + } + } + return newName; + } + } \ No newline at end of file