Skip to content

Commit

Permalink
Merge pull request #182 from aegif/integration
Browse files Browse the repository at this point in the history
version 2.3.7
  • Loading branch information
linzhixing committed Jan 8, 2016
2 parents 6462055 + 3d43a11 commit b211a38
Show file tree
Hide file tree
Showing 45 changed files with 3,193 additions and 2,915 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jetty.log
.settings
!.gitkeep
setup/installer/*/log
target
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>jp.aegif.nemaki</groupId>
<artifactId>core</artifactId>
<packaging>war</packaging>
<version>2.3.6</version>
<version>2.3.7</version>
<name>core</name>
<description>NemakiWare server</description>
<url>https://github.com/NemakiWare/NemakiWare</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -106,7 +107,7 @@ public class ContentServiceImpl implements ContentService {
private PropertyManager propertyManager;
private SolrUtil solrUtil;

private static final Log logger = LogFactory.getLog(ContentServiceImpl.class);
private static final Log log = LogFactory.getLog(ContentServiceImpl.class);
private final static String PATH_SEPARATOR = "/";

// ///////////////////////////////////////
Expand Down Expand Up @@ -166,12 +167,12 @@ public Content getContentByPath(String repositoryId, String path) {
// root
return contentDaoService.getFolder(repositoryId, rootId);
} else if (splittedPath.size() >= 1) {
Content content = contentDaoService.getFolderByPath(repositoryId, rootId);
Content content = contentDaoService.getFolder(repositoryId, rootId);
// Get the the leaf node
for (int i = 1; i < splittedPath.size(); i++) {
String leafName = splittedPath.get(i);
if (content == null) {
logger.warn("Leaf node '" + leafName + "' in path '" + path + "' is not found.");
log.warn("Leaf node '" + leafName + "' in path '" + path + "' is not found.");
return null;
} else {
Content child = contentDaoService.getChildByName(repositoryId, content.getId(), leafName);
Expand Down Expand Up @@ -437,7 +438,7 @@ public Document createDocument(CallContext callContext, String repositoryId, Pro
}
} catch (Exception ex) {
// not stop follow sequence
logger.error(ex);
log.error(ex);
}
}
}
Expand Down Expand Up @@ -522,6 +523,7 @@ public Document createDocumentWithNewStream(CallContext callContext, String repo
// Create
Document result = contentDaoService.create(repositoryId, copy);


// Record the change event
writeChangeEvent(callContext, repositoryId, result, ChangeType.CREATED);

Expand Down Expand Up @@ -1147,7 +1149,7 @@ private void setUpdatePropertyValue(String repositoryId, Content content, Proper
if (propertyData.getId().equals(PropertyIds.NAME)) {
if (DataUtil.getIdProperty(properties, PropertyIds.OBJECT_ID) != content.getId()) {
String uniqueName = buildUniqueName(repositoryId, DataUtil
.getStringProperty(properties, PropertyIds.NAME), content.getParentId(), content.getId());
.getStringProperty(properties, PropertyIds.NAME), content.getParentId(), content);
content.setName(uniqueName);
}
}
Expand Down Expand Up @@ -1301,7 +1303,7 @@ public List<String> deleteTree(CallContext callContext, String repositoryId, Str
failureIds.add(child.getId());
continue;
} else {
logger.error("", e);
log.error("", e);
}
}
}
Expand All @@ -1314,7 +1316,7 @@ public List<String> deleteTree(CallContext callContext, String repositoryId, Str
if (continueOnFailure) {
failureIds.add(folderId);
} else {
logger.error("", e);
log.error("", e);
}
}

Expand Down Expand Up @@ -1637,13 +1639,13 @@ public Archive createAttachmentArchive(CallContext callContext, String repositor
public void restoreArchive(String repositoryId, String archiveId) {
Archive archive = contentDaoService.getArchive(repositoryId, archiveId);
if (archive == null) {
logger.error("Archive does not exist!");
log.error("Archive does not exist!");
return;
}

// Check whether the destination does still extist.
if (!restorationTargetExists(repositoryId, archive)) {
logger.error("The destination of the restoration doesn't exist");
log.error("The destination of the restoration doesn't exist");
return;
}

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

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

return getDocument(repositoryId, archive.getOriginalId());
Expand Down Expand Up @@ -1721,55 +1723,33 @@ private Boolean restorationTargetExists(String repositoryId, Archive archive) {
// ///////////////////////////////////////
// Utility
// ///////////////////////////////////////
private String buildUniqueName(String repositoryId, String originalName, String folderId, String existingId) {
private String buildUniqueName(String repositoryId, String proposedName, String folderId, Content current) {
boolean bun = propertyManager.readBoolean(PropertyKey.CAPABILITY_EXTENDED_BUILD_UNIQUE_NAME);
if (!bun) {
return originalName;
}

List<Content> children = getChildren(repositoryId, folderId);

List<String> conflicts = new ArrayList<String>();
if (CollectionUtils.isEmpty(children)) {
return originalName;
} else {
// Get collection of conflict names
for (Content child : children) {
// Exclude update of existing content in the folder
if (nameConflicts(originalName, child.getName())) {
if (!child.getId().equals(existingId)) {
conflicts.add(child.getName());
}
}
}

if (CollectionUtils.isEmpty(conflicts)) {
return originalName;
} else {
// Insert unused suffix
String nameWithSuffix = originalName;
for (int i = 0; i < conflicts.size() + 1; i++) {
nameWithSuffix = buildNameWithSuffix(originalName, i + 1);
if (!conflicts.contains(nameWithSuffix)) {
break;
}
}
return nameWithSuffix;
return proposedName;
}

//Check if update method
if(current != null && current.getName().equals(proposedName)){
return proposedName;
}

List<String>names = contentDaoService.getChildrenNames(repositoryId, folderId);
String[] splitted = splitFileName(proposedName);
String originalNameBody = splitted[0];
String extension = splitted[1];

String newNameBody = originalNameBody;
for(Integer i = 1; i <= names.size(); i++){
if(names.contains(newNameBody + extension)){
newNameBody = originalNameBody + " ~" + i;
continue;
}else{
break;
}
}
}

private boolean nameConflicts(String originalName, String targetName) {
String[] original = splitFileName(originalName);
String[] target = splitFileName(targetName);

if (!original[1].equals(target[1]))
return false;
if (removeCopySuffix(original[0]).equals(removeCopySuffix(target[0]))) {
return true;
} else {
return false;
}

return newNameBody + extension;
}

private String[] splitFileName(String name) {
Expand All @@ -1790,23 +1770,6 @@ private String[] splitFileName(String name) {
return ary;
}

private String buildNameWithSuffix(String fileName, int suffixNumber) {
String[] split = splitFileName(fileName);
String inserted = split[0] + "(" + suffixNumber + ")" + split[1];
return inserted;
}

private String removeCopySuffix(String bodyOfFileName) {
String regexp = "\\([0-9]+\\)$";
Pattern pattern = Pattern.compile(regexp);
Matcher matcher = pattern.matcher(bodyOfFileName);
if (matcher.find()) {
return matcher.replaceFirst("");
} else {
return bodyOfFileName;
}
}

private String increasedVersionLabel(Document document, VersioningState versioningState) {
// e.g. #{major}(.{#minor})
String label = document.getVersionLabel();
Expand Down
Loading

0 comments on commit b211a38

Please sign in to comment.