Skip to content

Commit b211a38

Browse files
author
linzhixing
committed
Merge pull request #182 from aegif/integration
version 2.3.7
2 parents 6462055 + 3d43a11 commit b211a38

45 files changed

Lines changed: 3193 additions & 2915 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ jetty.log
77
.settings
88
!.gitkeep
99
setup/installer/*/log
10+
target

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>jp.aegif.nemaki</groupId>
66
<artifactId>core</artifactId>
77
<packaging>war</packaging>
8-
<version>2.3.6</version>
8+
<version>2.3.7</version>
99
<name>core</name>
1010
<description>NemakiWare server</description>
1111
<url>https://github.com/NemakiWare/NemakiWare</url>

core/src/main/java/jp/aegif/nemaki/businesslogic/impl/ContentServiceImpl.java

Lines changed: 37 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.ArrayList;
2828
import java.util.Arrays;
2929
import java.util.Collection;
30+
import java.util.Collections;
3031
import java.util.GregorianCalendar;
3132
import java.util.HashMap;
3233
import java.util.LinkedList;
@@ -106,7 +107,7 @@ public class ContentServiceImpl implements ContentService {
106107
private PropertyManager propertyManager;
107108
private SolrUtil solrUtil;
108109

109-
private static final Log logger = LogFactory.getLog(ContentServiceImpl.class);
110+
private static final Log log = LogFactory.getLog(ContentServiceImpl.class);
110111
private final static String PATH_SEPARATOR = "/";
111112

112113
// ///////////////////////////////////////
@@ -166,12 +167,12 @@ public Content getContentByPath(String repositoryId, String path) {
166167
// root
167168
return contentDaoService.getFolder(repositoryId, rootId);
168169
} else if (splittedPath.size() >= 1) {
169-
Content content = contentDaoService.getFolderByPath(repositoryId, rootId);
170+
Content content = contentDaoService.getFolder(repositoryId, rootId);
170171
// Get the the leaf node
171172
for (int i = 1; i < splittedPath.size(); i++) {
172173
String leafName = splittedPath.get(i);
173174
if (content == null) {
174-
logger.warn("Leaf node '" + leafName + "' in path '" + path + "' is not found.");
175+
log.warn("Leaf node '" + leafName + "' in path '" + path + "' is not found.");
175176
return null;
176177
} else {
177178
Content child = contentDaoService.getChildByName(repositoryId, content.getId(), leafName);
@@ -437,7 +438,7 @@ public Document createDocument(CallContext callContext, String repositoryId, Pro
437438
}
438439
} catch (Exception ex) {
439440
// not stop follow sequence
440-
logger.error(ex);
441+
log.error(ex);
441442
}
442443
}
443444
}
@@ -522,6 +523,7 @@ public Document createDocumentWithNewStream(CallContext callContext, String repo
522523
// Create
523524
Document result = contentDaoService.create(repositoryId, copy);
524525

526+
525527
// Record the change event
526528
writeChangeEvent(callContext, repositoryId, result, ChangeType.CREATED);
527529

@@ -1147,7 +1149,7 @@ private void setUpdatePropertyValue(String repositoryId, Content content, Proper
11471149
if (propertyData.getId().equals(PropertyIds.NAME)) {
11481150
if (DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID) != content.getId()) {
11491151
String uniqueName = buildUniqueName(repositoryId, DataUtil
1150-
.getStringProperty(properties, PropertyIds.NAME), content.getParentId(), content.getId());
1152+
.getStringProperty(properties, PropertyIds.NAME), content.getParentId(), content);
11511153
content.setName(uniqueName);
11521154
}
11531155
}
@@ -1301,7 +1303,7 @@ public List<String> deleteTree(CallContext callContext, String repositoryId, Str
13011303
failureIds.add(child.getId());
13021304
continue;
13031305
} else {
1304-
logger.error("", e);
1306+
log.error("", e);
13051307
}
13061308
}
13071309
}
@@ -1314,7 +1316,7 @@ public List<String> deleteTree(CallContext callContext, String repositoryId, Str
13141316
if (continueOnFailure) {
13151317
failureIds.add(folderId);
13161318
} else {
1317-
logger.error("", e);
1319+
log.error("", e);
13181320
}
13191321
}
13201322

@@ -1637,13 +1639,13 @@ public Archive createAttachmentArchive(CallContext callContext, String repositor
16371639
public void restoreArchive(String repositoryId, String archiveId) {
16381640
Archive archive = contentDaoService.getArchive(repositoryId, archiveId);
16391641
if (archive == null) {
1640-
logger.error("Archive does not exist!");
1642+
log.error("Archive does not exist!");
16411643
return;
16421644
}
16431645

16441646
// Check whether the destination does still extist.
16451647
if (!restorationTargetExists(repositoryId, archive)) {
1646-
logger.error("The destination of the restoration doesn't exist");
1648+
log.error("The destination of the restoration doesn't exist");
16471649
return;
16481650
}
16491651

@@ -1658,9 +1660,9 @@ public void restoreArchive(String repositoryId, String archiveId) {
16581660
Document restored = restoreDocument(repositoryId, archive);
16591661
writeChangeEvent(dummyContext, repositoryId, restored, ChangeType.CREATED);
16601662
} else if (archive.isAttachment()) {
1661-
logger.error("Attachment can't be restored alone");
1663+
log.error("Attachment can't be restored alone");
16621664
} else {
1663-
logger.error("Only document or folder is supported for restoration");
1665+
log.error("Only document or folder is supported for restoration");
16641666
}
16651667

16661668
// Call Solr indexing(optional)
@@ -1683,7 +1685,7 @@ private Document restoreDocument(String repositoryId, Archive archive) {
16831685
contentDaoService.deleteArchive(repositoryId, attachmentArchive.getId());
16841686
}
16851687
} catch (Exception e) {
1686-
logger.error("fail to restore a document", e);
1688+
log.error("fail to restore a document", e);
16871689
}
16881690

16891691
return getDocument(repositoryId, archive.getOriginalId());
@@ -1721,55 +1723,33 @@ private Boolean restorationTargetExists(String repositoryId, Archive archive) {
17211723
// ///////////////////////////////////////
17221724
// Utility
17231725
// ///////////////////////////////////////
1724-
private String buildUniqueName(String repositoryId, String originalName, String folderId, String existingId) {
1726+
private String buildUniqueName(String repositoryId, String proposedName, String folderId, Content current) {
17251727
boolean bun = propertyManager.readBoolean(PropertyKey.CAPABILITY_EXTENDED_BUILD_UNIQUE_NAME);
17261728
if (!bun) {
1727-
return originalName;
1728-
}
1729-
1730-
List<Content> children = getChildren(repositoryId, folderId);
1731-
1732-
List<String> conflicts = new ArrayList<String>();
1733-
if (CollectionUtils.isEmpty(children)) {
1734-
return originalName;
1735-
} else {
1736-
// Get collection of conflict names
1737-
for (Content child : children) {
1738-
// Exclude update of existing content in the folder
1739-
if (nameConflicts(originalName, child.getName())) {
1740-
if (!child.getId().equals(existingId)) {
1741-
conflicts.add(child.getName());
1742-
}
1743-
}
1744-
}
1745-
1746-
if (CollectionUtils.isEmpty(conflicts)) {
1747-
return originalName;
1748-
} else {
1749-
// Insert unused suffix
1750-
String nameWithSuffix = originalName;
1751-
for (int i = 0; i < conflicts.size() + 1; i++) {
1752-
nameWithSuffix = buildNameWithSuffix(originalName, i + 1);
1753-
if (!conflicts.contains(nameWithSuffix)) {
1754-
break;
1755-
}
1756-
}
1757-
return nameWithSuffix;
1729+
return proposedName;
1730+
}
1731+
1732+
//Check if update method
1733+
if(current != null && current.getName().equals(proposedName)){
1734+
return proposedName;
1735+
}
1736+
1737+
List<String>names = contentDaoService.getChildrenNames(repositoryId, folderId);
1738+
String[] splitted = splitFileName(proposedName);
1739+
String originalNameBody = splitted[0];
1740+
String extension = splitted[1];
1741+
1742+
String newNameBody = originalNameBody;
1743+
for(Integer i = 1; i <= names.size(); i++){
1744+
if(names.contains(newNameBody + extension)){
1745+
newNameBody = originalNameBody + " ~" + i;
1746+
continue;
1747+
}else{
1748+
break;
17581749
}
17591750
}
1760-
}
1761-
1762-
private boolean nameConflicts(String originalName, String targetName) {
1763-
String[] original = splitFileName(originalName);
1764-
String[] target = splitFileName(targetName);
1765-
1766-
if (!original[1].equals(target[1]))
1767-
return false;
1768-
if (removeCopySuffix(original[0]).equals(removeCopySuffix(target[0]))) {
1769-
return true;
1770-
} else {
1771-
return false;
1772-
}
1751+
1752+
return newNameBody + extension;
17731753
}
17741754

17751755
private String[] splitFileName(String name) {
@@ -1790,23 +1770,6 @@ private String[] splitFileName(String name) {
17901770
return ary;
17911771
}
17921772

1793-
private String buildNameWithSuffix(String fileName, int suffixNumber) {
1794-
String[] split = splitFileName(fileName);
1795-
String inserted = split[0] + "(" + suffixNumber + ")" + split[1];
1796-
return inserted;
1797-
}
1798-
1799-
private String removeCopySuffix(String bodyOfFileName) {
1800-
String regexp = "\\([0-9]+\\)$";
1801-
Pattern pattern = Pattern.compile(regexp);
1802-
Matcher matcher = pattern.matcher(bodyOfFileName);
1803-
if (matcher.find()) {
1804-
return matcher.replaceFirst("");
1805-
} else {
1806-
return bodyOfFileName;
1807-
}
1808-
}
1809-
18101773
private String increasedVersionLabel(Document document, VersioningState versioningState) {
18111774
// e.g. #{major}(.{#minor})
18121775
String label = document.getVersionLabel();

0 commit comments

Comments
 (0)