diff --git a/account-management-db-model/pom.xml b/account-management-db-model/pom.xml index 080915c..8b48688 100644 --- a/account-management-db-model/pom.xml +++ b/account-management-db-model/pom.xml @@ -1,32 +1,33 @@ - + - - org.duracloud.db - db - 4.2.0-SNAPSHOT - ../pom.xml - - - 4.0.0 + org.duracloud.db - account-management-db-model + db 4.2.0-SNAPSHOT - Account DB Model + ../pom.xml + + + 4.0.0 + org.duracloud.db + account-management-db-model + 4.2.0-SNAPSHOT + Account DB Model - - - org.hibernate.javax.persistence - hibernate-jpa-2.1-api - + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + - - org.springframework.security - spring-security-core - + + org.springframework.security + spring-security-core + - - org.apache.commons - commons-lang3 - - + + org.apache.commons + commons-lang3 + + diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountInfo.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountInfo.java index c207298..43922a6 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountInfo.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountInfo.java @@ -8,7 +8,6 @@ package org.duracloud.account.db.model; import java.util.Set; - import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -53,7 +52,6 @@ public enum AccountStatus { @Enumerated(EnumType.STRING) private AccountStatus status; - /** * The StorageProviderAccount which is used for primary storage */ @@ -64,7 +62,7 @@ public enum AccountStatus { /** * The StorageProviderAccounts which are used for secondary storage */ - @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }) + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @JoinColumn(name = "account_info_id", nullable = true, columnDefinition = "bigint(20)") private Set secondaryStorageProviderAccounts; @@ -113,7 +111,7 @@ public StorageProviderAccount getPrimaryStorageProviderAccount() { } public void setPrimaryStorageProviderAccount( - StorageProviderAccount primaryStorageProviderAccount) { + StorageProviderAccount primaryStorageProviderAccount) { this.primaryStorageProviderAccount = primaryStorageProviderAccount; } @@ -122,11 +120,10 @@ public Set getSecondaryStorageProviderAccounts() { } public void setSecondaryStorageProviderAccounts( - Set secondaryStorageProviderAccounts) { + Set secondaryStorageProviderAccounts) { this.secondaryStorageProviderAccounts = secondaryStorageProviderAccounts; } - @Override public int compareTo(AccountInfo o) { return this.acctName.compareTo(o.acctName); diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountRights.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountRights.java index bd4470e..ae3ac58 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountRights.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/AccountRights.java @@ -8,7 +8,6 @@ package org.duracloud.account.db.model; import java.util.Set; - import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -21,24 +20,24 @@ /** * @author Erik Paulsson - * Date: 7/10/13 + * Date: 7/10/13 */ @Entity public class AccountRights extends BaseEntity { - @ManyToOne(fetch=FetchType.EAGER, optional=false) - @JoinColumn(name="account_id", nullable=false, columnDefinition = "bigint(20)") + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @JoinColumn(name = "account_id", nullable = false, columnDefinition = "bigint(20)") private AccountInfo account; - @ManyToOne(fetch= FetchType.EAGER, optional=true) - @JoinColumn(name="user_id", nullable=true, columnDefinition = "bigint(20)") + @ManyToOne(fetch = FetchType.EAGER, optional = true) + @JoinColumn(name = "user_id", nullable = true, columnDefinition = "bigint(20)") private DuracloudUser user; - @ElementCollection(targetClass=Role.class, fetch = FetchType.EAGER) + @ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER) @Enumerated(EnumType.STRING) - @CollectionTable(name="account_rights_role", - joinColumns=@JoinColumn(name="account_rights_id", columnDefinition = "bigint(20)")) - @Column(name="role") + @CollectionTable(name = "account_rights_role", + joinColumns = @JoinColumn(name = "account_rights_id", columnDefinition = "bigint(20)")) + @Column(name = "role") private Set roles; public AccountInfo getAccount() { diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/BaseEntity.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/BaseEntity.java index 3c8999a..047b407 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/BaseEntity.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/BaseEntity.java @@ -8,7 +8,6 @@ package org.duracloud.account.db.model; import java.util.Date; - import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -18,17 +17,16 @@ /** * @author Erik Paulsson - * Date: 7/10/13 + * Date: 7/10/13 */ @MappedSuperclass public abstract class BaseEntity { @Id - @GeneratedValue(strategy=GenerationType.AUTO) - @Column(columnDefinition="bigint(20) AUTO_INCREMENT") + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(columnDefinition = "bigint(20) AUTO_INCREMENT") protected Long id; - @Version private Date modified; @@ -50,12 +48,18 @@ public void setModified(Date modified) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } BaseEntity that = (BaseEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (id != null ? !id.equals(that.id) : that.id != null) { + return false; + } return true; } diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudGroup.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudGroup.java index bc0072a..cdc97fe 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudGroup.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudGroup.java @@ -8,7 +8,6 @@ package org.duracloud.account.db.model; import java.util.Set; - import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -18,7 +17,7 @@ /** * @author Erik Paulsson - * Date: 7/10/13 + * Date: 7/10/13 */ @Entity public class DuracloudGroup extends BaseEntity { @@ -28,14 +27,16 @@ public class DuracloudGroup extends BaseEntity { private String name; - @ManyToMany(fetch=FetchType.EAGER) - @JoinTable(name="group_user", - joinColumns=@JoinColumn(name="group_id", referencedColumnName="id", columnDefinition = "bigint(20)"), - inverseJoinColumns=@JoinColumn(name="user_id", referencedColumnName="id", columnDefinition = "bigint(20)")) + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "group_user", + joinColumns = @JoinColumn(name = "group_id", referencedColumnName = "id", + columnDefinition = "bigint(20)"), + inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id", + columnDefinition = "bigint(20)")) private Set users; - @ManyToOne(fetch=FetchType.LAZY, optional=false) - @JoinColumn(name="account_id", nullable=false, columnDefinition = "bigint(20)") + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "account_id", nullable = false, columnDefinition = "bigint(20)") private AccountInfo account; public String getName() { @@ -45,9 +46,9 @@ public String getName() { public void setName(String name) { this.name = name; } - - public String getPrettyName(){ - return this.name.substring(this.name.indexOf(PREFIX)+PREFIX.length()); + + public String getPrettyName() { + return this.name.substring(this.name.indexOf(PREFIX) + PREFIX.length()); } public Set getUsers() { diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudMill.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudMill.java index d3f4bc6..4ec1f34 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudMill.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudMill.java @@ -12,68 +12,81 @@ /** * Contains basic configuration information for interacting with the Duracloud Mill. + * * @author Daniel Bernstein - * Date: 05/06/2015 + * Date: 05/06/2015 */ @Entity public class DuracloudMill extends BaseEntity { - @Column(nullable=false) + @Column(nullable = false) private String dbName; - @Column(nullable=false) + @Column(nullable = false) private String dbHost; - @Column(nullable=false) + @Column(nullable = false) private Integer dbPort; - @Column(nullable=false) + @Column(nullable = false) private String dbUsername; - @Column(nullable=false) + @Column(nullable = false) private String dbPassword; - @Column(nullable=false) + @Column(nullable = false) private String auditQueue; - @Column(nullable=false) + @Column(nullable = false) private String auditLogSpaceId; - + public String getDbName() { return dbName; } + public void setDbName(String dbName) { this.dbName = dbName; } + public String getDbHost() { return dbHost; } + public void setDbHost(String dbHost) { this.dbHost = dbHost; } + public Integer getDbPort() { return dbPort; } + public void setDbPort(Integer dbPort) { this.dbPort = dbPort; } + public String getDbUsername() { return dbUsername; } + public void setDbUsername(String dbUsername) { this.dbUsername = dbUsername; } + public String getDbPassword() { return dbPassword; } + public void setDbPassword(String dbPassword) { this.dbPassword = dbPassword; } + public String getAuditQueue() { return auditQueue; } + public void setAuditQueue(String auditQueue) { this.auditQueue = auditQueue; } + public String getAuditLogSpaceId() { return auditLogSpaceId; } + public void setAuditLogSpaceId(String auditLogSpaceId) { this.auditLogSpaceId = auditLogSpaceId; } - - + } diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudUser.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudUser.java index 3dd6f44..2fb414b 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudUser.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/DuracloudUser.java @@ -10,7 +10,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; - import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -22,7 +21,7 @@ /** * @author Erik Paulsson - * Date: 7/10/13 + * Date: 7/10/13 */ @Entity public class DuracloudUser extends BaseEntity implements UserDetails { @@ -39,13 +38,13 @@ public class DuracloudUser extends BaseEntity implements UserDetails { private boolean accountNonExpired = true; private boolean credentialsNonExpired = true; private boolean accountNonLocked = true; - + /** * A CIDR formatted IP Range. */ - private String allowableIPAddressRange; + private String allowableIPAddressRange; - @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="user") + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "user") private Set accountRights; private boolean root = false; @@ -168,8 +167,8 @@ public Collection getAuthorities() { } } } - - if(isRoot()){ + + if (isRoot()) { authorities.add(new SimpleGrantedAuthority(Role.ROLE_ROOT.name())); } return authorities; @@ -184,15 +183,15 @@ public Set getRolesByAcct(Long accountId) { } } } - - if(isRoot()){ + + if (isRoot()) { roles.addAll(Role.ROLE_ROOT.getRoleHierarchy()); } return roles; } public Role getRoleByAcct(Long accountId) { - if(isRoot()){ + if (isRoot()) { return Role.ROLE_ROOT; } Set roles = getRolesByAcct(accountId); @@ -219,7 +218,7 @@ public boolean hasRoleForAcct(Long accountId, Role role) { public boolean isRootUser() { return root; } - + public boolean isRoot() { return root; } diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/GlobalProperties.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/GlobalProperties.java index 3b0a12b..336c154 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/GlobalProperties.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/GlobalProperties.java @@ -12,32 +12,32 @@ /** * A grab bag of global properties. + * * @author Daniel Bernstein - * Date: 01/05/2016 + * Date: 01/05/2016 */ @Entity public class GlobalProperties extends BaseEntity { /* * an SNS topic arn for sending noticiations to the instances */ - @Column(nullable=false) + @Column(nullable = false) private String instanceNotificationTopicArn; - @Column(nullable=false) + @Column(nullable = false) private String cloudFrontAccountId; - @Column(nullable=false) + @Column(nullable = false) private String cloudFrontKeyId; - @Column(nullable=false) + @Column(nullable = false) private String cloudFrontKeyPath; public String getInstanceNotificationTopicArn() { return instanceNotificationTopicArn; } - public void setInstanceNotificationTopicArn( - String instanceNotificationTopicArn) { + public void setInstanceNotificationTopicArn(String instanceNotificationTopicArn) { this.instanceNotificationTopicArn = instanceNotificationTopicArn; } @@ -63,6 +63,6 @@ public String getCloudFrontKeyPath() { public void setCloudFrontKeyPath(String cloudFrontKeyPath) { this.cloudFrontKeyPath = cloudFrontKeyPath; - } - + } + } diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/Identifiable.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/Identifiable.java index 93bda88..1d1fe14 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/Identifiable.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/Identifiable.java @@ -9,9 +9,10 @@ /** * @author Erik Paulsson - * Date: 7/10/13 + * Date: 7/10/13 */ public interface Identifiable { public Long getId(); + public void setId(Long id); } diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/InstanceType.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/InstanceType.java index 9ed276c..0f8c9fc 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/InstanceType.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/InstanceType.java @@ -11,7 +11,6 @@ * Represents different instance sizes available on which to deploy duracloud. * * @author Daniel Bernstein - * */ public enum InstanceType { SMALL, diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/Role.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/Role.java index fb3a039..2a76adb 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/Role.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/Role.java @@ -15,7 +15,7 @@ /** * @author Erik Paulsson - * Date: 7/10/13 + * Date: 7/10/13 */ public enum Role { ROLE_INIT("Init"), @@ -46,18 +46,25 @@ public Set getRoleHierarchy() { switch (this) { case ROLE_ROOT: hierarchy.add(ROLE_ROOT); + // fall through case ROLE_OWNER: hierarchy.add(ROLE_OWNER); + // fall through case ROLE_ADMIN: hierarchy.add(ROLE_ADMIN); + // fall through case ROLE_USER: hierarchy.add(ROLE_USER); + // fall through case ROLE_ANONYMOUS: hierarchy.add(ROLE_ANONYMOUS); break; case ROLE_INIT: // not in hierarchy hierarchy.add(ROLE_INIT); + break; + default: + break; } return hierarchy; diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/StorageProviderAccount.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/StorageProviderAccount.java index e6f5837..c4cb7f2 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/StorageProviderAccount.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/StorageProviderAccount.java @@ -8,7 +8,6 @@ package org.duracloud.account.db.model; import java.util.Map; - import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -23,7 +22,7 @@ /** * @author Erik Paulsson - * Date: 7/10/13 + * Date: 7/10/13 */ @Entity public class StorageProviderAccount extends ProviderAccount { @@ -35,18 +34,18 @@ public class StorageProviderAccount extends ProviderAccount { @Enumerated(EnumType.STRING) private StorageProviderType providerType; - @ElementCollection(fetch=FetchType.EAGER) - @MapKeyColumn (name="map_key") - @CollectionTable(name ="storage_provider_account_properties", - joinColumns=@JoinColumn(name="storage_provider_account_id")) - @Column(name="map_value") - private Map properties; - + @ElementCollection(fetch = FetchType.EAGER) + @MapKeyColumn(name = "map_key") + @CollectionTable(name = "storage_provider_account_properties", + joinColumns = @JoinColumn(name = "storage_provider_account_id")) + @Column(name = "map_value") + private Map properties; + /** * The max GBs of storage allowable for the account. */ private int storageLimit = 1; - + public StorageProviderType getProviderType() { return providerType; } @@ -55,11 +54,11 @@ public void setProviderType(StorageProviderType providerType) { this.providerType = providerType; } - public Map getProperties() { + public Map getProperties() { return properties; } - public void setProperties(Map properties) { + public void setProperties(Map properties) { this.properties = properties; } diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/UserInvitation.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/UserInvitation.java index 0f0bbeb..068978c 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/UserInvitation.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/UserInvitation.java @@ -8,7 +8,6 @@ package org.duracloud.account.db.model; import java.util.Date; - import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -16,13 +15,13 @@ /** * @author Erik Paulsson - * Date: 7/11/13 + * Date: 7/11/13 */ @Entity public class UserInvitation extends BaseEntity { - @ManyToOne(fetch= FetchType.EAGER, optional=true) - @JoinColumn(name="account_id", nullable=true, columnDefinition = "bigint(20)") + @ManyToOne(fetch = FetchType.EAGER, optional = true) + @JoinColumn(name = "account_id", nullable = true, columnDefinition = "bigint(20)") private AccountInfo account; private String accountName; @@ -35,12 +34,12 @@ public class UserInvitation extends BaseEntity { private Date expirationDate; private String redemptionCode; - public UserInvitation() {} + public UserInvitation() { + } - public UserInvitation( - Long id, AccountInfo account, String accountName, String accountOrg, String accountDep, - String accountSubdomain, String adminUsername, String userEmail, - int expirationDays, String redemptionCode) { + public UserInvitation(Long id, AccountInfo account, String accountName, String accountOrg, String accountDep, + String accountSubdomain, String adminUsername, String userEmail, int expirationDays, + String redemptionCode) { this.id = id; this.account = account; this.accountName = accountName; @@ -139,19 +138,15 @@ public void setRedemptionCode(String redemptionCode) { this.redemptionCode = redemptionCode; } - - - - @Override public String toString() { return "UserInvitation[id=" - + id + ", accountId=" + account.getId() + ", accountName=" + accountName - + ", accountOrg=" + accountOrg + ", accountDep=" + accountDep - + ", accountSubdomain=" + accountSubdomain + ", adminUsername=" + adminUsername - + ", userEmail=" + userEmail - + ", creationDate=" + creationDate + ", expirationDate=" - + expirationDate + ", redemptionCode=" + redemptionCode + "]"; + + id + ", accountId=" + account.getId() + ", accountName=" + accountName + + ", accountOrg=" + accountOrg + ", accountDep=" + accountDep + + ", accountSubdomain=" + accountSubdomain + ", adminUsername=" + adminUsername + + ", userEmail=" + userEmail + + ", creationDate=" + creationDate + ", expirationDate=" + + expirationDate + ", redemptionCode=" + redemptionCode + "]"; } } diff --git a/account-management-db-model/src/main/java/org/duracloud/account/db/model/util/DuracloudAccount.java b/account-management-db-model/src/main/java/org/duracloud/account/db/model/util/DuracloudAccount.java index 1b9fbc6..c66247c 100644 --- a/account-management-db-model/src/main/java/org/duracloud/account/db/model/util/DuracloudAccount.java +++ b/account-management-db-model/src/main/java/org/duracloud/account/db/model/util/DuracloudAccount.java @@ -7,22 +7,21 @@ */ package org.duracloud.account.db.model.util; +import java.util.Set; + import org.duracloud.account.db.model.AccountInfo; import org.duracloud.account.db.model.InstanceType; import org.duracloud.account.db.model.Role; -import java.util.Set; - public class DuracloudAccount implements Comparable { private AccountInfo accountInfo; - private String instanceStatus; private String instanceVersion; private InstanceType instanceType; - + private Set versions; private Role userRole; @@ -43,7 +42,6 @@ public void setAccountInfo(AccountInfo accountInfo) { this.accountInfo = accountInfo; } - public String getInstanceStatus() { return instanceStatus; } diff --git a/account-management-db-model/src/main/java/org/duracloud/reportdata/bitintegrity/BitIntegrityReportResult.java b/account-management-db-model/src/main/java/org/duracloud/reportdata/bitintegrity/BitIntegrityReportResult.java index f50f067..8695424 100644 --- a/account-management-db-model/src/main/java/org/duracloud/reportdata/bitintegrity/BitIntegrityReportResult.java +++ b/account-management-db-model/src/main/java/org/duracloud/reportdata/bitintegrity/BitIntegrityReportResult.java @@ -6,10 +6,9 @@ * http://duracloud.org/license/ */ package org.duracloud.reportdata.bitintegrity; + /** - * * @author Daniel Bernstein - * */ public enum BitIntegrityReportResult { SUCCESS, diff --git a/account-management-db-model/src/main/java/org/duracloud/security/domain/SecurityUserBean.java b/account-management-db-model/src/main/java/org/duracloud/security/domain/SecurityUserBean.java index 10421ea..c395e0d 100644 --- a/account-management-db-model/src/main/java/org/duracloud/security/domain/SecurityUserBean.java +++ b/account-management-db-model/src/main/java/org/duracloud/security/domain/SecurityUserBean.java @@ -7,14 +7,14 @@ */ package org.duracloud.security.domain; -import org.apache.commons.lang3.StringUtils; - import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; + /** * @author Andrew Woods - * Date: Mar 28, 2010 + * Date: Mar 28, 2010 */ public class SecurityUserBean { private String username; @@ -135,7 +135,7 @@ public void setEmail(String email) { } public void setIpLimits(String ipLimits) { - if(!StringUtils.isBlank(ipLimits)) { + if (!StringUtils.isBlank(ipLimits)) { this.ipLimits = ipLimits; } } diff --git a/account-management-db-model/src/main/java/org/duracloud/storage/domain/StorageProviderType.java b/account-management-db-model/src/main/java/org/duracloud/storage/domain/StorageProviderType.java index dd5463c..7b23fbd 100644 --- a/account-management-db-model/src/main/java/org/duracloud/storage/domain/StorageProviderType.java +++ b/account-management-db-model/src/main/java/org/duracloud/storage/domain/StorageProviderType.java @@ -28,7 +28,7 @@ private StorageProviderType(String pt) { public static StorageProviderType fromString(String pt) { for (StorageProviderType pType : values()) { - if (pType.text.equalsIgnoreCase(pt)|| + if (pType.text.equalsIgnoreCase(pt) || pType.name().equalsIgnoreCase(pt)) { return pType; } @@ -41,7 +41,7 @@ public String toString() { return text; } - public String getName(){ + public String getName() { return name(); } } diff --git a/account-management-db-repo/pom.xml b/account-management-db-repo/pom.xml index 3060185..5c948b3 100644 --- a/account-management-db-repo/pom.xml +++ b/account-management-db-repo/pom.xml @@ -3,53 +3,53 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - org.duracloud.db - db - 4.2.0-SNAPSHOT - ../pom.xml - - - 4.0.0 + org.duracloud.db - account-management-db-repo + db 4.2.0-SNAPSHOT - Account DB Repositories - - - - org.duracloud.db - account-management-db-model - ${project.version} - - - - org.duracloud.db - common - ${project.version} - - - - - org.hibernate - hibernate-entitymanager - - - - org.springframework.data - spring-data-jpa - - - - org.apache.commons - commons-dbcp2 - - - - mysql - mysql-connector-java - - - + ../pom.xml + + + 4.0.0 + org.duracloud.db + account-management-db-repo + 4.2.0-SNAPSHOT + Account DB Repositories + + + + org.duracloud.db + account-management-db-model + ${project.version} + + + + org.duracloud.db + common + ${project.version} + + + + + org.hibernate + hibernate-entitymanager + + + + org.springframework.data + spring-data-jpa + + + + org.apache.commons + commons-dbcp2 + + + + mysql + mysql-connector-java + + + diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/config/AccountJpaRepoConfig.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/config/AccountJpaRepoConfig.java index aca633c..c83ca02 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/config/AccountJpaRepoConfig.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/config/AccountJpaRepoConfig.java @@ -8,8 +8,6 @@ package org.duracloud.account.db.config; import java.text.MessageFormat; -import java.util.Properties; - import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; @@ -24,20 +22,16 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.Database; import org.springframework.orm.jpa.vendor.HibernateJpaDialect; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; /** - * * @author Daniel Bernstein - * */ @Configuration -@EnableJpaRepositories(basePackages = { "org.duracloud.account.db" }, - entityManagerFactoryRef = AccountJpaRepoConfig.ENTITY_MANAGER_FACTORY_BEAN, +@EnableJpaRepositories(basePackages = {"org.duracloud.account.db"}, + entityManagerFactoryRef = AccountJpaRepoConfig.ENTITY_MANAGER_FACTORY_BEAN, transactionManagerRef = AccountJpaRepoConfig.TRANSACTION_MANAGER_BEAN) @EnableTransactionManagement public class AccountJpaRepoConfig { @@ -49,17 +43,17 @@ public class AccountJpaRepoConfig { "accountJpaRepoTransactionManager"; public static final String ENTITY_MANAGER_FACTORY_BEAN = ACCOUNT_REPO_ENTITY_MANAGER_FACTORY_BEAN; - + @Autowired private Environment env; - + @Bean(name = ACCOUNT_REPO_DATA_SOURCE_BEAN, destroyMethod = "close") public BasicDataSource accountRepoDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(MessageFormat.format("jdbc:mysql://{0}:{1}/{2}" + - "?characterEncoding=utf8" + - "&characxterSetResults=utf8", + "?characterEncoding=utf8" + + "&characxterSetResults=utf8", env.getProperty(ConfigConstants.MC_DB_HOST, "localhost"), env.getProperty(ConfigConstants.MC_DB_PORT, "3306"), env.getProperty(ConfigConstants.MC_DB_NAME, "name"))); @@ -71,9 +65,9 @@ public BasicDataSource accountRepoDataSource() { } @Primary - @Bean(name=TRANSACTION_MANAGER_BEAN) - public PlatformTransactionManager - accountRepoTransactionManager(@Qualifier(ACCOUNT_REPO_ENTITY_MANAGER_FACTORY_BEAN) EntityManagerFactory entityManagerFactory) { + @Bean(name = TRANSACTION_MANAGER_BEAN) + public PlatformTransactionManager accountRepoTransactionManager( + @Qualifier(ACCOUNT_REPO_ENTITY_MANAGER_FACTORY_BEAN) EntityManagerFactory entityManagerFactory) { JpaTransactionManager tm = new JpaTransactionManager(entityManagerFactory); tm.setJpaDialect(new HibernateJpaDialect()); @@ -81,18 +75,16 @@ public BasicDataSource accountRepoDataSource() { } @Bean(name = ACCOUNT_REPO_ENTITY_MANAGER_FACTORY_BEAN) - public LocalContainerEntityManagerFactoryBean - accountRepoEntityManagerFactory(@Qualifier(ACCOUNT_REPO_DATA_SOURCE_BEAN) DataSource dataSource) { + public LocalContainerEntityManagerFactoryBean accountRepoEntityManagerFactory( + @Qualifier(ACCOUNT_REPO_DATA_SOURCE_BEAN) DataSource dataSource) { LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource); emf.setPersistenceUnitName("account-repo-pu"); emf.setPackagesToScan("org.duracloud.account.db"); - - JpaConfigurationUtil.configureEntityManagerFactory(env,emf); + JpaConfigurationUtil.configureEntityManagerFactory(env, emf); return emf; } - } diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/config/ConfigConstants.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/config/ConfigConstants.java index ee0bfdc..fb374e9 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/config/ConfigConstants.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/config/ConfigConstants.java @@ -6,12 +6,16 @@ * http://duracloud.org/license/ */ package org.duracloud.account.db.config; + /** - * * @author Daniel Bernstein - * */ public class ConfigConstants { + + private ConfigConstants() { + // Ensures class is not instantiated, as only static values exist + } + public static final String MC_DB_NAME = "db.name"; public static final String MC_DB_HOST = "db.host"; public static final String MC_DB_PORT = "db.port"; diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudAccountRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudAccountRepo.java index 5cb2ac9..18af5f9 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudAccountRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudAccountRepo.java @@ -7,17 +7,18 @@ */ package org.duracloud.account.db.repo; +import java.util.List; + import org.duracloud.account.db.model.AccountInfo; import org.duracloud.account.db.model.AccountInfo.AccountStatus; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; /** * @author Erik Paulsson - * Date: 7/8/13 + * Date: 7/8/13 */ -@Repository(value="accountRepo") +@Repository(value = "accountRepo") public interface DuracloudAccountRepo extends JpaRepository { /** @@ -31,20 +32,18 @@ public interface DuracloudAccountRepo extends JpaRepository { /** * This method returns the account with the given subdomain * - * @param status + * @param status * @return list of account info */ public List findByStatus(AccountStatus status); /** - * * @param id * @return */ public AccountInfo findByPrimaryStorageProviderAccountId(Long id); /** - * * @param id * @return */ diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudGroupRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudGroupRepo.java index 4c15672..6ff2d0f 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudGroupRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudGroupRepo.java @@ -7,24 +7,24 @@ */ package org.duracloud.account.db.repo; +import java.util.List; + import org.duracloud.account.db.model.DuracloudGroup; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - /** * @author Erik Paulsson - * Date: 7/8/13 + * Date: 7/8/13 */ -@Repository(value="groupRepo") +@Repository(value = "groupRepo") public interface DuracloudGroupRepo extends JpaRepository { /** * This method returns a single group within the given account, with the * given groupname. * - * @param name of group + * @param name of group * @param accountId associated with group * @return group */ diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudMillRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudMillRepo.java index f7b850a..45c4f75 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudMillRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudMillRepo.java @@ -13,9 +13,9 @@ /** * @author Daniel Bernstein - * Date: 05/06/2015 + * Date: 05/06/2015 */ -@Repository(value="duracloudMillRepo") +@Repository(value = "duracloudMillRepo") public interface DuracloudMillRepo extends JpaRepository { - + } diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRepoMgr.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRepoMgr.java index 8b618e3..156084f 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRepoMgr.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRepoMgr.java @@ -7,18 +7,18 @@ */ package org.duracloud.account.db.repo; +import java.util.HashSet; +import java.util.Set; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Component; -import java.util.HashSet; -import java.util.Set; - /** * @author Erik Paulsson - * Date: 7/17/13 + * Date: 7/17/13 */ -@Component(value="repoMgr") +@Component(value = "repoMgr") public class DuracloudRepoMgr { @Autowired @@ -62,12 +62,10 @@ public DuracloudUserInvitationRepo getUserInvitationRepo() { return userInvitationRepo; } - public DuracloudStorageProviderAccountRepo getStorageProviderAccountRepo() { return storageProviderAccountRepo; } - public Set getAllRepos() { Set repos = new HashSet<>(); repos.add(userRepo); diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRightsRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRightsRepo.java index 7cc1680..7fde1b3 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRightsRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudRightsRepo.java @@ -7,18 +7,18 @@ */ package org.duracloud.account.db.repo; +import java.util.List; + import org.duracloud.account.db.model.AccountRights; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - /** * @author Erik Paulsson - * Date: 7/8/13 + * Date: 7/8/13 */ -@Repository(value="rightsRepo") -public interface DuracloudRightsRepo extends JpaRepository{ +@Repository(value = "rightsRepo") +public interface DuracloudRightsRepo extends JpaRepository { /** * This method returns the set of rights for a given account @@ -46,7 +46,6 @@ public interface DuracloudRightsRepo extends JpaRepository{ * @return rights */ public AccountRights findByAccountIdAndUserId(Long accountId, - Long userId); - + Long userId); } diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudStorageProviderAccountRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudStorageProviderAccountRepo.java index c7f5a8e..6046616 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudStorageProviderAccountRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudStorageProviderAccountRepo.java @@ -13,9 +13,9 @@ /** * @author Erik Paulsson - * Date: 7/9/13 + * Date: 7/9/13 */ -@Repository(value="storageProviderAccountRepo") +@Repository(value = "storageProviderAccountRepo") public interface DuracloudStorageProviderAccountRepo extends JpaRepository { } diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserInvitationRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserInvitationRepo.java index bf43076..d207a8f 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserInvitationRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserInvitationRepo.java @@ -7,17 +7,17 @@ */ package org.duracloud.account.db.repo; +import java.util.List; + import org.duracloud.account.db.model.UserInvitation; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - /** * @author Erik Paulsson - * Date: 7/9/13 + * Date: 7/9/13 */ -@Repository(value="userInvitationRepo") +@Repository(value = "userInvitationRepo") public interface DuracloudUserInvitationRepo extends JpaRepository { /** diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserRepo.java index 004bb64..b2d9225 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/DuracloudUserRepo.java @@ -15,9 +15,9 @@ /** * @author Erik Paulsson - * Date: 7/3/13 + * Date: 7/3/13 */ -@Repository(value="userRepo") +@Repository(value = "userRepo") public interface DuracloudUserRepo extends JpaRepository { /** @@ -27,10 +27,12 @@ public interface DuracloudUserRepo extends JpaRepository { * @return user */ public DuracloudUser findByUsername(String username); - + /** - * Returns all enabled, non-locked root users with non-expired credentials. + * Returns all enabled, non-locked root users with non-expired credentials. + * * @return */ - public List findByRootTrueAndEnabledTrueAndAccountNonExpiredTrueAndCredentialsNonExpiredTrueAndAccountNonLockedTrue(); + public List + findByRootTrueAndEnabledTrueAndAccountNonExpiredTrueAndCredentialsNonExpiredTrueAndAccountNonLockedTrue(); } diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/GlobalPropertiesRepo.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/GlobalPropertiesRepo.java index 6e34a37..4685e80 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/GlobalPropertiesRepo.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/GlobalPropertiesRepo.java @@ -13,9 +13,9 @@ /** * @author Daniel Bernstein - * Date: 05/06/2015 + * Date: 05/06/2015 */ -@Repository(value="globalPropertiesRepo") +@Repository(value = "globalPropertiesRepo") public interface GlobalPropertiesRepo extends JpaRepository { - + } diff --git a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/UserFinderUtil.java b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/UserFinderUtil.java index b275918..2c09335 100644 --- a/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/UserFinderUtil.java +++ b/account-management-db-repo/src/main/java/org/duracloud/account/db/repo/UserFinderUtil.java @@ -32,9 +32,8 @@ public UserFinderUtil(DuracloudRepoMgr repoMgr) { /** * Retrieves the users associated with the account - * + * * @param account for which users should be gathered - * @return the set of users associated with an account */ public Set getAccountUsers(AccountInfo account) { @@ -54,7 +53,7 @@ public Set getAccountUsers(AccountInfo account) { user.setAccountRights(accountOnlyRightsSet); users.add(user); } - + List rootUsers = repoMgr.getUserRepo() .findByRootTrueAndEnabledTrueAndAccountNonExpiredTrueAndCredentialsNonExpiredTrueAndAccountNonLockedTrue(); @@ -62,9 +61,10 @@ public Set getAccountUsers(AccountInfo account) { users.addAll(rootUsers); return users; } - + public Set convertDuracloudUsersToSecurityUserBeans(AccountInfo accountInfo, - Set users, boolean includeRootUsers) { + Set users, + boolean includeRootUsers) { // collect groups for the account Long accountId = accountInfo.getId(); DuracloudGroupRepo groupRepo = repoMgr.getGroupRepo(); @@ -80,11 +80,11 @@ public Set convertDuracloudUsersToSecurityUserBeans(AccountInf String ipLimits = annotateAddressRange(accountInfo, user.getAllowableIPAddressRange()); Set roles = user.getRolesByAcct(accountId); - if(roles == null) { + if (roles == null) { roles = new HashSet(); } - if(roles.isEmpty()) { + if (roles.isEmpty()) { roles.add(Role.ROLE_USER); } @@ -93,16 +93,16 @@ public Set convertDuracloudUsersToSecurityUserBeans(AccountInf grants.add(role.name()); } - if(!user.isRoot() || includeRootUsers) { + if (!user.isRoot() || includeRootUsers) { SecurityUserBean bean = - new SecurityUserBean(username, password, grants); + new SecurityUserBean(username, password, grants); bean.setEmail(email); bean.setIpLimits(ipLimits); - if(groups != null) { + if (groups != null) { for (DuracloudGroup group : groups) { Set grpUsers = group.getUsers(); - if(grpUsers.contains(user)) { + if (grpUsers.contains(user)) { bean.addGroup(group.getName()); } } @@ -112,7 +112,7 @@ public Set convertDuracloudUsersToSecurityUserBeans(AccountInf } } return userBeans; - } + } /** * For a user account with an IP limitation, this method is used to update @@ -124,7 +124,7 @@ public Set convertDuracloudUsersToSecurityUserBeans(AccountInf * @return baseRange plus the instance elastic IP, or null if baseRange is null */ private String annotateAddressRange(AccountInfo accountInfo, String baseRange) { - if(null == baseRange || baseRange.equals("")) { + if (null == baseRange || baseRange.equals("")) { return baseRange; } else { return baseRange; // delimeter + elasticIp + "/32"; diff --git a/common/pom.xml b/common/pom.xml index 7420b25..2b5e5e9 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.duracloud.db @@ -9,7 +9,7 @@ org.duracloud.db - db + db 4.2.0-SNAPSHOT ../pom.xml @@ -30,11 +30,11 @@ net.sf.trove4j trove4j - + - commons-codec - commons-codec - + commons-codec + commons-codec + org.hibernate diff --git a/common/src/main/java/org/duracloud/common/collection/StreamingIterator.java b/common/src/main/java/org/duracloud/common/collection/StreamingIterator.java index cee6555..7a4eeb6 100644 --- a/common/src/main/java/org/duracloud/common/collection/StreamingIterator.java +++ b/common/src/main/java/org/duracloud/common/collection/StreamingIterator.java @@ -14,51 +14,51 @@ import java.util.Queue; /** - * An {code Iterator} implementation that delegates its underlying data provider to an + * An {code Iterator} implementation that delegates its underlying data provider to an * {code IteratorSource}. It is useful for implementing an iterator that iterates over - * a collection of items of indeterminate size. - * @author Daniel Bernstein - * + * a collection of items of indeterminate size. + * * @param + * @author Daniel Bernstein */ -public class StreamingIterator implements Iterator{ +public class StreamingIterator implements Iterator { private Queue queue = new LinkedList(); - + private IteratorSource source; - - public StreamingIterator(IteratorSource source){ + + public StreamingIterator(IteratorSource source) { this.source = source; } - + @Override public synchronized boolean hasNext() { - if(!queue.isEmpty()){ + if (!queue.isEmpty()) { return true; - } - + } + Collection chunk = source.getNext(); - if(chunk != null){ + if (chunk != null) { Iterator it = chunk.iterator(); - while(it.hasNext()){ + while (it.hasNext()) { T item = it.next(); queue.add(item); } } - - if(queue.size() > 0){ + + if (queue.size() > 0) { return true; } - + return false; } @Override public T next() { - if(hasNext()){ + if (hasNext()) { return queue.remove(); } - + throw new NoSuchElementException(); } diff --git a/common/src/main/java/org/duracloud/common/collection/WriteOnlyStringSet.java b/common/src/main/java/org/duracloud/common/collection/WriteOnlyStringSet.java index e8dc7bc..674e6aa 100644 --- a/common/src/main/java/org/duracloud/common/collection/WriteOnlyStringSet.java +++ b/common/src/main/java/org/duracloud/common/collection/WriteOnlyStringSet.java @@ -7,42 +7,42 @@ */ package org.duracloud.common.collection; -import gnu.trove.set.hash.THashSet; - import java.security.MessageDigest; +import gnu.trove.set.hash.THashSet; import org.apache.commons.codec.digest.DigestUtils; /** - * This class gives you an efficient way to write to an in memory set-like structure of tens of - * millions of strings. The catch is that once you write the strings to the set, + * This class gives you an efficient way to write to an in memory set-like structure of tens of + * millions of strings. The catch is that once you write the strings to the set, * you can't retrieve them. However you can ask if the set contains any string. Additionally - * you can remove strings from the set as well as determine the set's size. - * + * you can remove strings from the set as well as determine the set's size. + * * An example use case: You're comparing two large sets (A and B) of objects both of which won't fit in memory. - * You want to be able to load A (each element of which can be reduced to a string value) into memory - * and then iterate over B, checking for existence in A (probably of a single property of each B element) before + * You want to be able to load A (each element of which can be reduced to a string value) into memory + * and then iterate over B, checking for existence in A (probably of a single property of each B element) before * performing some further logic on that B element. - * + * * @author Daniel Bernstein - * Date: May 22, 2015 + * Date: May 22, 2015 */ public class WriteOnlyStringSet { - private THashSet set; - public WriteOnlyStringSet(int capacity){ + private THashSet set; + + public WriteOnlyStringSet(int capacity) { set = new THashSet(capacity); } - + private static final MessageDigest MD5 = DigestUtils.getMd5Digest(); - public void add(String string){ - if(string == null){ + public void add(String string) { + if (string == null) { return; } - + set.add(getMd5String(string)); } - + private String getMd5String(String string) { return checksumBytesToString(MD5.digest(string.getBytes())); } @@ -53,9 +53,9 @@ private String getMd5String(String string) { */ public static String checksumBytesToString(byte[] digestBytes) { StringBuffer hexString = new StringBuffer(); - for (int i=0; i * @param + * @author Daniel Bernstein + * Date: Sep 3, 2014 */ public abstract class JpaIteratorSource implements IteratorSource { private int currentPage = 0; private int maxResults; private R repo; - public JpaIteratorSource(R repo, int maxResults){ + public JpaIteratorSource(R repo, int maxResults) { this.repo = repo; - if(maxResults <= 0){ + if (maxResults <= 0) { throw new IllegalArgumentException("maxResults must be greater than 0"); } this.maxResults = maxResults; } - public JpaIteratorSource(R repo){ + public JpaIteratorSource(R repo) { this(repo, 1000); } - + @Override public Collection getNext() { - if(currentPage < 0){ + if (currentPage < 0) { return null; } - Page page = getNextPage(new PageRequest(currentPage, maxResults), repo); + Page page = getNextPage(new PageRequest(currentPage, maxResults), repo); currentPage++; - if(page.getTotalPages() == currentPage){ + if (page.getTotalPages() == currentPage) { currentPage = -1; } - + return page.getContent(); - + } - + /** * Specific Jpa call goes here. + * * @param pageable * @return */ diff --git a/common/src/main/java/org/duracloud/common/db/error/NotFoundException.java b/common/src/main/java/org/duracloud/common/db/error/NotFoundException.java index 7bed0fb..c2fcf73 100644 --- a/common/src/main/java/org/duracloud/common/db/error/NotFoundException.java +++ b/common/src/main/java/org/duracloud/common/db/error/NotFoundException.java @@ -14,7 +14,7 @@ */ public class NotFoundException extends Exception { - public NotFoundException (String message) { + public NotFoundException(String message) { super(message); } diff --git a/common/src/main/java/org/duracloud/common/db/hibernate/PhysicalNamingStrategyImpl.java b/common/src/main/java/org/duracloud/common/db/hibernate/PhysicalNamingStrategyImpl.java index c53df7d..4753819 100644 --- a/common/src/main/java/org/duracloud/common/db/hibernate/PhysicalNamingStrategyImpl.java +++ b/common/src/main/java/org/duracloud/common/db/hibernate/PhysicalNamingStrategyImpl.java @@ -11,33 +11,29 @@ * In the move from hibernate 4.x to 5.x the naming strategies changed and are no longer backwards compatible. * This fix is based on the solution provided by Samuel Andres here: * http://stackoverflow.com/questions/32437202/improvednamingstrategy-no-longer-working-in-hibernate-5 - * - * + * * @author Daniel Bernstein */ public class PhysicalNamingStrategyImpl extends PhysicalNamingStrategyStandardImpl implements Serializable { public static final PhysicalNamingStrategyImpl INSTANCE = new PhysicalNamingStrategyImpl(); - + @Override public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) { return new Identifier(addUnderscores(name.getText()), name.isQuoted()); } - + @Override public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) { return new Identifier(addUnderscores(name.getText()), name.isQuoted()); } - - + protected static String addUnderscores(String name) { - final StringBuilder buf = new StringBuilder( name.replace('.', '_') ); - for (int i=1; i source; - + @After - public void teartDown(){ + public void teartDown() { verifyAll(); } - + @Test public void test() { - EasyMock.expect(source.getNext()).andReturn(Arrays.asList("1","2", "3")); - EasyMock.expect(source.getNext()).andReturn(Arrays.asList("4","5", "6")); + EasyMock.expect(source.getNext()).andReturn(Arrays.asList("1", "2", "3")); + EasyMock.expect(source.getNext()).andReturn(Arrays.asList("4", "5", "6")); EasyMock.expect(source.getNext()).andReturn(null); replayAll(); StreamingIterator it = new StreamingIterator(source); int count = 0; - while(it.hasNext()){ + while (it.hasNext()) { it.next(); count++; } Assert.assertEquals(6, count); } - @Test public void testNullSource() { EasyMock.expect(source.getNext()).andReturn(null); replayAll(); StreamingIterator it = new StreamingIterator(source); int count = 0; - while(it.hasNext()){ + while (it.hasNext()) { it.next(); count++; } Assert.assertEquals(0, count); } - + @Test public void testNextOnEmptyIterator() { EasyMock.expect(source.getNext()).andReturn(null); replayAll(); StreamingIterator it = new StreamingIterator(source); - - try{ + + try { it.next(); Assert.fail(); - }catch(NoSuchElementException ex){ + } catch (NoSuchElementException ex) { + // Expected exception } } - + @Test public void testRemoveNotSupported() { StreamingIterator it = new StreamingIterator(source); replayAll(); - try{ + try { it.remove(); Assert.fail(); - }catch(UnsupportedOperationException ex){ + } catch (UnsupportedOperationException ex) { + // Expected exception } } diff --git a/common/src/test/java/org/duracloud/common/collection/WriteOnlyStringSetTest.java b/common/src/test/java/org/duracloud/common/collection/WriteOnlyStringSetTest.java index 387c11b..0d075a3 100644 --- a/common/src/test/java/org/duracloud/common/collection/WriteOnlyStringSetTest.java +++ b/common/src/test/java/org/duracloud/common/collection/WriteOnlyStringSetTest.java @@ -7,17 +7,18 @@ */ package org.duracloud.common.collection; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; - - /** * @author Daniel Bernstein - * Date: May 22, 2015 + * Date: May 22, 2015 */ public class WriteOnlyStringSetTest { @@ -38,26 +39,25 @@ public void tearDown() throws Exception { @Test public void test() { int capacity = 100; - + WriteOnlyStringSet set = new WriteOnlyStringSet(capacity); String idPrefix = StringUtils.repeat("a", 200); - for (int i = 0; i < capacity; i++){ - set.add(idPrefix.concat(i+"")); + for (int i = 0; i < capacity; i++) { + set.add(idPrefix.concat(i + "")); } - - assertEquals(capacity, set.size()); + assertEquals(capacity, set.size()); - for (int i = 0; i < capacity; i++){ - assertTrue(set.contains(idPrefix.concat(i+""))); + for (int i = 0; i < capacity; i++) { + assertTrue(set.contains(idPrefix.concat(i + ""))); } - for (int i = 0; i < capacity; i++){ - set.remove(idPrefix.concat(i+"")); + for (int i = 0; i < capacity; i++) { + set.remove(idPrefix.concat(i + "")); } - for (int i = 0; i < capacity; i++){ - assertFalse(set.contains(idPrefix.concat(i+""))); + for (int i = 0; i < capacity; i++) { + assertFalse(set.contains(idPrefix.concat(i + ""))); } assertEquals(0, set.size()); @@ -66,16 +66,16 @@ public void test() { @Test public void testAdditionOf1MillionItemsTakesLessThan200Seconds() { long start = System.currentTimeMillis(); - int capacity = 1000*1000*1; - + int capacity = 1000 * 1000 * 1; + WriteOnlyStringSet set = new WriteOnlyStringSet(capacity); String idPrefix = StringUtils.repeat("a", 200); - for (int i = 0; i < capacity; i++){ - set.add(idPrefix.concat(i+"")); + for (int i = 0; i < capacity; i++) { + set.add(idPrefix.concat(i + "")); } - + assertEquals(capacity, set.size()); - assertTrue(System.currentTimeMillis()-start < 20*1000); + assertTrue(System.currentTimeMillis() - start < 20 * 1000); } /** diff --git a/mill-db-repo/pom.xml b/mill-db-repo/pom.xml index b29ea58..e350a99 100644 --- a/mill-db-repo/pom.xml +++ b/mill-db-repo/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.duracloud.db diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogItem.java b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogItem.java index 5c8371f..29c950c 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogItem.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogItem.java @@ -9,89 +9,77 @@ /** * An intereface defining a log item. - * + * * @author Daniel Bernstein - * */ public interface AuditLogItem { /** - * * @return */ public String getAccount(); /** - * * @return */ public String getStoreId(); /** - * * @return */ public String getSpaceId(); /** - * * @return */ public String getContentId(); /** - * * @return */ public String getContentMd5(); /** - * @return - */ - public String getMimetype(); + * @return + */ + public String getMimetype(); - /* - * - * @return - */ - public String getContentSize(); + /* + * + * @return + */ + public String getContentSize(); - /** - * - * @return - */ - public String getContentProperties(); + /** + * @return + */ + public String getContentProperties(); - /** - * - * @return - */ - public String getSpaceAcls(); - - /** - * + /** + * @return + */ + public String getSpaceAcls(); + + /** * @return */ public String getAction(); /** - * * @return */ public String getUsername(); - + /** - * * @return */ public String getSourceSpaceId(); /** - * * @return */ public String getSourceContentId(); + /** - * * @return */ public long getTimestamp(); diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogStore.java b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogStore.java index 4efb339..bd8fc65 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogStore.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogStore.java @@ -9,7 +9,6 @@ import java.util.Date; import java.util.Iterator; -import java.util.Map; import org.duracloud.common.db.error.NotFoundException; @@ -22,6 +21,7 @@ public interface AuditLogStore { /** * This method writes the logItem to the audit log. + * * @param account * @param storeId * @param spaceId @@ -50,10 +50,10 @@ public void write(String account, String sourceSpaceId, String sourceContentId, Date timestamp) throws AuditLogWriteFailedException; - - + /** * Retrieves log history for a content item. + * * @param account * @param storeId * @param spaceId @@ -67,6 +67,7 @@ public Iterator getLogItems(String account, /** * Retrieves log history for a content item in chronological order + * * @param account * @param storeId * @param spaceId @@ -74,16 +75,17 @@ public Iterator getLogItems(String account, * @return */ public AuditLogItem getLatestLogItem(String account, - String storeId, - String spaceId, - String contentId) throws NotFoundException; - + String storeId, + String spaceId, + String contentId) throws NotFoundException; + /** * Adds the following properties to the specified item. + * * @param item * @param properties * @throws AuditLogWriteFailedException */ public void updateProperties(AuditLogItem item, String properties) throws AuditLogWriteFailedException; - + } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogWriteFailedException.java b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogWriteFailedException.java index 6700e52..512414d 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogWriteFailedException.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/AuditLogWriteFailedException.java @@ -9,7 +9,7 @@ /** * @author Daniel Bernstein - * March 11, 2014 + * March 11, 2014 */ public class AuditLogWriteFailedException extends Exception { diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStore.java b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStore.java index 0e5d51a..cecacd4 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStore.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStore.java @@ -11,16 +11,15 @@ import java.util.Iterator; import java.util.List; -import org.duracloud.mill.auditor.AuditLogItem; -import org.duracloud.mill.auditor.AuditLogStore; -import org.duracloud.mill.auditor.AuditLogWriteFailedException; import org.duracloud.common.collection.StreamingIterator; import org.duracloud.common.collection.jpa.JpaIteratorSource; import org.duracloud.common.db.error.NotFoundException; +import org.duracloud.mill.auditor.AuditLogItem; +import org.duracloud.mill.auditor.AuditLogStore; +import org.duracloud.mill.auditor.AuditLogWriteFailedException; import org.duracloud.mill.db.model.JpaAuditLogItem; import org.duracloud.mill.db.repo.JpaAuditLogItemRepo; import org.duracloud.mill.db.repo.MillJpaRepoConfig; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -31,9 +30,7 @@ import org.springframework.util.CollectionUtils; /** - * * @author Daniel Bernstein - * */ public class JpaAuditLogStore implements AuditLogStore { private static Logger log = LoggerFactory.getLogger(JpaAuditLogStore.class); @@ -83,50 +80,51 @@ public void write(String account, log.debug("item saved: {}", item); } catch (Exception ex) { - if(ex instanceof org.springframework.dao.DataIntegrityViolationException){ - log.warn("failed to add audit log item {}: due to data integrity violation: suspected duplicate record: -> message={}", - ex.getMessage()); - }else{ + if (ex instanceof org.springframework.dao.DataIntegrityViolationException) { + log.warn( + "failed to add audit log item {}: due to data integrity violation: suspected duplicate record: ->" + + " message={}", + ex.getMessage()); + } else { throw new AuditLogWriteFailedException(ex, item); } } } - @Override @Transactional(value = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN, readOnly = true) public Iterator getLogItems(final String account, final String storeId, final String spaceId, final String contentId) { - return (Iterator) new StreamingIterator(new JpaIteratorSource(auditLogRepo) { - @Override - protected Page getNextPage(Pageable pageable, JpaAuditLogItemRepo repo) { - return repo + return (Iterator) new StreamingIterator( + new JpaIteratorSource(auditLogRepo) { + @Override + protected Page getNextPage(Pageable pageable, JpaAuditLogItemRepo repo) { + return repo .findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByContentIdAsc(account, storeId, spaceId, contentId, pageable); - } - }); + } + }); } @Override @Transactional(value = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN, readOnly = true) - public AuditLogItem - getLatestLogItem(String account, - String storeId, - String spaceId, - String contentId) throws NotFoundException { + public AuditLogItem getLatestLogItem(String account, + String storeId, + String spaceId, + String contentId) throws NotFoundException { List result = auditLogRepo - .findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByTimestampDesc(account, - storeId, - spaceId, - contentId); - if(!CollectionUtils.isEmpty(result)){ + .findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByTimestampDesc(account, + storeId, + spaceId, + contentId); + if (!CollectionUtils.isEmpty(result)) { return result.get(0); - }else{ + } else { return null; } } @@ -134,17 +132,17 @@ protected Page getNextPage(Pageable pageable, JpaAuditLogItemRe @Override @Transactional(value = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN, propagation = Propagation.REQUIRES_NEW) public void updateProperties(AuditLogItem item, String properties) - throws AuditLogWriteFailedException { - - if(!(item instanceof JpaAuditLogItem)){ + throws AuditLogWriteFailedException { + + if (!(item instanceof JpaAuditLogItem)) { throw new AuditLogWriteFailedException("audit log item must be of type " + "JpaAuditLogItem when used with this " + "implementation: item is of type " + item.getClass().getCanonicalName(), item); } - Long id = ((JpaAuditLogItem)item).getId(); - - JpaAuditLogItem refreshedItem = auditLogRepo.findOne(id); + Long id = ((JpaAuditLogItem) item).getId(); + + JpaAuditLogItem refreshedItem = auditLogRepo.findOne(id); refreshedItem.setContentProperties(properties); auditLogRepo.saveAndFlush(refreshedItem); } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BaseEntity.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BaseEntity.java index e8b5675..d4d32b5 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BaseEntity.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BaseEntity.java @@ -8,39 +8,35 @@ package org.duracloud.mill.db.model; import java.util.Date; - import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import javax.persistence.Version; import javax.persistence.MappedSuperclass; +import javax.persistence.Version; import org.apache.commons.lang3.builder.ToStringBuilder; /** - * * @author Daniel Bernstein - * */ @MappedSuperclass public abstract class BaseEntity { @Id - @GeneratedValue(strategy=GenerationType.AUTO) - @Column(columnDefinition="bigint(20) AUTO_INCREMENT") + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(columnDefinition = "bigint(20) AUTO_INCREMENT") protected Long id; - - @Column(nullable=false, columnDefinition="datetime(3) NOT NULL") + @Column(nullable = false, columnDefinition = "datetime(3) NOT NULL") private Date modified; @Version @Column(nullable = false, columnDefinition = "int NOT NULL DEFAULT 0") private int version; - public Long getId() { + public Long getId() { return id; } @@ -58,16 +54,21 @@ public void setModified(Date modified) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } BaseEntity that = (BaseEntity) o; - if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (id != null ? !id.equals(that.id) : that.id != null) { + return false; + } return true; } - public int getVersion() { return version; @@ -81,12 +82,12 @@ public void setVersion(int version) { public int hashCode() { return id != null ? id.hashCode() : 0; } - + /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { - return ToStringBuilder.reflectionToString(this); + return ToStringBuilder.reflectionToString(this); } } \ No newline at end of file diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BitIntegrityReport.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BitIntegrityReport.java index 778bda1..ed6e01b 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BitIntegrityReport.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/BitIntegrityReport.java @@ -8,7 +8,6 @@ package org.duracloud.mill.db.model; import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -19,74 +18,89 @@ /** * @author Daniel Bernstein - * Date: Sep 2, 2014 + * Date: Sep 2, 2014 */ @Entity @Table(name = "bit_report") public class BitIntegrityReport extends BaseEntity { - @Column(nullable=false) + @Column(nullable = false) private String account; - @Column(nullable=false) + @Column(nullable = false) private String storeId; - @Column(nullable=false) + @Column(nullable = false) private String spaceId; - @Column(nullable=false, length=1024) + @Column(nullable = false, length = 1024) private String reportContentId; - @Column(nullable=false) + @Column(nullable = false) private Date completionDate; - @Column(nullable=false) + @Column(nullable = false) private String reportSpaceId; - + private boolean display = true; - + @Enumerated(EnumType.STRING) private BitIntegrityReportResult result; - + public String getAccount() { return account; } + public void setAccount(String account) { this.account = account; } + public String getStoreId() { return storeId; } + public void setStoreId(String storeId) { this.storeId = storeId; } + public String getSpaceId() { return spaceId; } + public void setSpaceId(String spaceId) { this.spaceId = spaceId; } + public String getReportContentId() { return reportContentId; } + public void setReportContentId(String reportContentId) { this.reportContentId = reportContentId; } + public Date getCompletionDate() { return completionDate; } + public void setCompletionDate(Date completionDate) { this.completionDate = completionDate; } + public BitIntegrityReportResult getResult() { return result; } + public void setResult(BitIntegrityReportResult result) { this.result = result; } + public String getReportSpaceId() { return reportSpaceId; } + public void setReportSpaceId(String reportSpaceId) { this.reportSpaceId = reportSpaceId; } + public boolean isDisplay() { return display; } + public void setDisplay(boolean display) { this.display = display; } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/JpaAuditLogItem.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/JpaAuditLogItem.java index eee4273..ae56b80 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/JpaAuditLogItem.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/JpaAuditLogItem.java @@ -18,45 +18,43 @@ import org.duracloud.mill.auditor.AuditLogItem; /** - * * @author Daniel Bernstein - * */ @Entity @Table(name = "audit_log_item", - uniqueConstraints = @UniqueConstraint(columnNames = { "uniqueKey"})) + uniqueConstraints = @UniqueConstraint(columnNames = {"uniqueKey"})) public class JpaAuditLogItem extends BaseEntity implements AuditLogItem { - @Column(nullable=false) + @Column(nullable = false) private String account; - @Column(nullable=false) + @Column(nullable = false) private String storeId; - @Column(nullable=false) + @Column(nullable = false) private String spaceId; - @Column(length=1024) + @Column(length = 1024) private String contentId; private String contentMd5; private String mimetype; private String contentSize; - @Column(length=2048) + @Column(length = 2048) private String contentProperties; - @Column(length=2048) + @Column(length = 2048) private String spaceAcls; - @Column(nullable=false) + @Column(nullable = false) private String action; - @Column(nullable=false) + @Column(nullable = false) private String username; private String sourceSpaceId; private String sourceContentId; private String uniqueKey; - + /* * indicates whether or not the item has been written to file. */ - private boolean written = false; - - @Column(nullable=false) + private boolean written = false; + + @Column(nullable = false) private Long timestamp; - + @Override public String getAccount() { return this.account; @@ -183,14 +181,14 @@ public void setTimestamp(Long timestamp) { this.timestamp = timestamp; } - @Column(columnDefinition="char(32) NOT NULL") + @Column(columnDefinition = "char(32) NOT NULL") @Access(AccessType.PROPERTY) public String getUniqueKey() { - if(uniqueKey == null){ + if (uniqueKey == null) { this.uniqueKey = DigestUtils.md5Hex(this.action + "/" + this.account + "/" - + this.storeId + "/" + this.spaceId + "/" - + (this.contentId == null ? " " : this.contentId) + "/" - + this.timestamp); + + this.storeId + "/" + this.spaceId + "/" + + (this.contentId == null ? " " : this.contentId) + "/" + + this.timestamp); } return uniqueKey; } @@ -206,6 +204,5 @@ public boolean isWritten() { public void setWritten(boolean written) { this.written = written; } - - + } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/ManifestItem.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/ManifestItem.java index f847a04..0dda6ef 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/ManifestItem.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/ManifestItem.java @@ -18,25 +18,25 @@ /** * @author Daniel Bernstein - * Date: Sep 2, 2014 + * Date: Sep 2, 2014 */ @Entity @Table(name = "manifest_item", - uniqueConstraints = @UniqueConstraint(columnNames = { "uniqueKey"})) + uniqueConstraints = @UniqueConstraint(columnNames = {"uniqueKey"})) public class ManifestItem extends BaseEntity { - @Column(nullable=false) + @Column(nullable = false) private String account; - @Column(nullable=false) + @Column(nullable = false) private String storeId; - @Column(nullable=false) + @Column(nullable = false) private String spaceId; - @Column(nullable=false, length=1024) + @Column(nullable = false, length = 1024) private String contentId; - @Column(nullable=false) + @Column(nullable = false) private String contentChecksum; - @Column(nullable=false) + @Column(nullable = false) private String contentSize; - @Column(nullable=false) + @Column(nullable = false) private String contentMimetype; /** @@ -46,58 +46,65 @@ public class ManifestItem extends BaseEntity { * resolve itself. However, it is also possible that the item was deleted * directly on the storage provider and thus the inconsistency will not * resolve itself. - * + * * Thus the missingFromStorageProvider field is used by the bit integrity space listing verification * process to indicate a suspected problem. If the space listing verification encounters * an item in the manifest that is not in the storage provider AND the missingFromStorageProvider is * set to true, an error will be logged. - * */ private boolean missingFromStorageProvider = false; - + private boolean deleted = false; private String uniqueKey; - public String getAccount() { return account; } + public void setAccount(String account) { this.account = account; } + public String getStoreId() { return storeId; } + public void setStoreId(String storeId) { this.storeId = storeId; } + public String getSpaceId() { return spaceId; } + public void setSpaceId(String spaceId) { this.spaceId = spaceId; } + public String getContentId() { return contentId; } + public void setContentId(String contentId) { this.contentId = contentId; } + public String getContentChecksum() { return contentChecksum; } + public void setContentChecksum(String contentChecksum) { this.contentChecksum = contentChecksum; } - + @Access(AccessType.PROPERTY) - @Column(columnDefinition="char(32) NOT NULL") + @Column(columnDefinition = "char(32) NOT NULL") public String getUniqueKey() { - if(uniqueKey == null){ + if (uniqueKey == null) { this.uniqueKey = DigestUtils.md5Hex(this.account + "/" + - this.storeId + "/" + - this.spaceId + "/"+ + this.storeId + "/" + + this.spaceId + "/" + this.contentId); } return uniqueKey; @@ -106,27 +113,35 @@ public String getUniqueKey() { public void setUniqueKey(String uniqueKey) { this.uniqueKey = uniqueKey; } + public boolean isDeleted() { return deleted; } + public void setDeleted(boolean deleted) { this.deleted = deleted; } + public String getContentMimetype() { return contentMimetype; } + public void setContentMimetype(String contentMimetype) { this.contentMimetype = contentMimetype; } + public String getContentSize() { return contentSize; } + public void setContentSize(String contentSize) { this.contentSize = contentSize; } + public boolean isMissingFromStorageProvider() { return missingFromStorageProvider; } + public void setMissingFromStorageProvider(boolean missingFromStorageProvider) { this.missingFromStorageProvider = missingFromStorageProvider; } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/SpaceStats.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/SpaceStats.java index 46ac810..e251c31 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/model/SpaceStats.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/model/SpaceStats.java @@ -8,32 +8,31 @@ package org.duracloud.mill.db.model; import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; /** * Represents a space's byte and object count at a moment in time. - * @author Daniel Bernstein * + * @author Daniel Bernstein */ @Entity public class SpaceStats extends BaseEntity { - - @Column(nullable=false, length=100) + + @Column(nullable = false, length = 100) private String accountId; - @Column(nullable=false, length=63) + @Column(nullable = false, length = 63) private String spaceId; - @Column(nullable=false, length=10) + @Column(nullable = false, length = 10) private String storeId; - @Column(nullable=false) + @Column(nullable = false) private long byteCount = 0; - @Column(nullable=false) + @Column(nullable = false) private long objectCount = 0; - - - public SpaceStats (){} - + + public SpaceStats() { + } + public SpaceStats(Date modified, String account, String storeId, String spaceId, long byteCount, long objectCount) { setModified(modified); setAccountId(account); @@ -42,34 +41,43 @@ public SpaceStats(Date modified, String account, String storeId, String spaceId, setByteCount(byteCount); setObjectCount(objectCount); } - + public String getSpaceId() { return spaceId; } + public void setSpaceId(String spaceId) { this.spaceId = spaceId; } + public String getStoreId() { return storeId; } + public void setStoreId(String storeId) { this.storeId = storeId; } + public String getAccountId() { return accountId; } + public void setAccountId(String accountId) { this.accountId = accountId; } + public long getByteCount() { return byteCount; } + public void setByteCount(long byteCount) { this.byteCount = byteCount; } + public long getObjectCount() { return objectCount; } + public void setObjectCount(long objectCount) { this.objectCount = objectCount; } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaAuditLogItemRepo.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaAuditLogItemRepo.java index cad4cc4..9df8641 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaAuditLogItemRepo.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaAuditLogItemRepo.java @@ -17,26 +17,22 @@ import org.springframework.stereotype.Repository; /** - * * @author Daniel Bernstein - * */ -@Repository(value="auditLogItemRepo") +@Repository(value = "auditLogItemRepo") public interface JpaAuditLogItemRepo extends JpaRepository { public Page findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByContentIdAsc( - @Param("account") String account, - @Param("storeId") String storeId, - @Param("spaceId") String spaceId, - @Param("spaceId") String contentId, - Pageable pageable); + @Param("account") String account, + @Param("storeId") String storeId, + @Param("spaceId") String spaceId, + @Param("spaceId") String contentId, + Pageable pageable); - public List findByWrittenFalseOrderByTimestampAsc(Pageable pageable); - - + public Long deleteByWrittenTrueAndTimestampLessThan(long timestamp); - + /** * @param account * @param storeId @@ -44,14 +40,13 @@ public Page findByAccountAndStoreIdAndSpaceIdAndContentIdOrderB * @param contentId * @return */ - public List - findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByTimestampDesc(String account, - String storeId, - String spaceId, - String contentId); + public List findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByTimestampDesc(String account, + String storeId, + String spaceId, + String contentId); public Page findByAccountAndSpaceIdOrderByTimestampAsc(String account, - String spaceId, - Pageable pageable); + String spaceId, + Pageable pageable); } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaBitIntegrityReportRepo.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaBitIntegrityReportRepo.java index 4688cd3..43b0114 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaBitIntegrityReportRepo.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaBitIntegrityReportRepo.java @@ -12,12 +12,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; /** - * * @author Daniel Bernstein - * */ @Repository(value = "bitIntegrityReportRepo") public interface JpaBitIntegrityReportRepo @@ -30,13 +27,11 @@ public interface JpaBitIntegrityReportRepo * @return */ - Page - findByStoreIdAndSpaceIdAndDisplayTrueOrderByCompletionDateDesc(String storeId, - String spaceId, - Pageable pageable); + Page findByStoreIdAndSpaceIdAndDisplayTrueOrderByCompletionDateDesc(String storeId, + String spaceId, + Pageable pageable); /** - * * @param account * @param storeId * @param spaceId diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaManifestItemRepo.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaManifestItemRepo.java index 91369da..35f6754 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaManifestItemRepo.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaManifestItemRepo.java @@ -20,13 +20,10 @@ import org.springframework.stereotype.Repository; /** - * * @author Daniel Bernstein - * */ @Repository(value = "manifestItemRepo") -public interface JpaManifestItemRepo extends - JpaRepository { +public interface JpaManifestItemRepo extends JpaRepository { /** * @param account @@ -35,45 +32,42 @@ public interface JpaManifestItemRepo extends * @param pageable * @return */ - Page - findByAccountAndStoreIdAndSpaceIdAndDeletedFalseOrderByContentIdAsc(String account, - String storeId, - String spaceId, - Pageable pageable); + Page findByAccountAndStoreIdAndSpaceIdAndDeletedFalseOrderByContentIdAsc(String account, + String storeId, + String spaceId, + Pageable pageable); /** - * * @param account * @param storeId * @param spaceId - * @param lastId - * The last id of the previous page. If there was no previous - * page, we recommend that you use the minimum id minus 1 in the - * unpaged set for optimum performance. + * @param lastId The last id of the previous page. If there was no previous + * page, we recommend that you use the minimum id minus 1 in the + * unpaged set for optimum performance. * @param limit * @return */ - @Query(nativeQuery=true,value="select * from manifest_item where account = ?1 and store_id=?2 and " - + "space_id = ?3 and deleted = false and id > ?4 order by id limit ?5") - List - findByAccountAndStoreIdAndSpaceIdAndDeletedFalse(String account, - String storeId, - String spaceId, - long lastId, - int limit); + @Query(nativeQuery = true, value = "select * from manifest_item where account = ?1 and store_id=?2 and " + + "space_id = ?3 and deleted = false and id > ?4 order by id limit ?5") + List findByAccountAndStoreIdAndSpaceIdAndDeletedFalse(String account, + String storeId, + String spaceId, + long lastId, + int limit); /** * Returns the minimum id value for the specified data set. + * * @param account * @param storeId * @param spaceId * @return */ - @Query(nativeQuery=true,value="select ifnull(min(id),0) from manifest_item where account = ?1 and store_id=?2 and " - + "space_id = ?3 and deleted = false") - long getMinId(String account, String storeId, String spaceId); + @Query(nativeQuery = true, + value = "select ifnull(min(id),0) from manifest_item where account = ?1 and store_id=?2 and " + + "space_id = ?3 and deleted = false") + long getMinId(String account, String storeId, String spaceId); - /** * @param account * @param storeId @@ -81,40 +75,37 @@ public interface JpaManifestItemRepo extends * @param contentId * @return */ - ManifestItem - findByAccountAndStoreIdAndSpaceIdAndContentId(String account, - String storeId, - String spaceId, - String contentId); + ManifestItem findByAccountAndStoreIdAndSpaceIdAndContentId(String account, + String storeId, + String spaceId, + String contentId); /** * @param expiration */ @Modifying - @Query(nativeQuery=true,value="delete from manifest_item where deleted = true and modified < ?1 limit 50000") + @Query(nativeQuery = true, value = "delete from manifest_item where deleted = true and modified < ?1 limit 50000") int deleteFirst50000ByDeletedTrueAndModifiedBefore(Date expiration); void deleteByAccountAndStoreIdAndSpaceId(String account, String storeId, String spaceId); - /** * Returns an array with the following values: [item_count,byte_count] + * * @param account * @param storeId * @param spaceId * @return */ - @Query(nativeQuery=true, - value="select count(*) objectCount, sum(content_size) as byteCount " - + "from manifest_item " - + "where account = :account and store_id = :storeId and " - + "space_id= :spaceId and deleted=false") - public Object[] getStorageStatsByAccountAndStoreIdAndSpaceId(@Param("account")String account, - @Param("storeId")String storeId, - @Param("spaceId")String spaceId); - - + @Query(nativeQuery = true, + value = "select count(*) objectCount, sum(content_size) as byteCount " + + "from manifest_item " + + "where account = :account and store_id = :storeId and " + + "space_id= :spaceId and deleted=false") + public Object[] getStorageStatsByAccountAndStoreIdAndSpaceId(@Param("account") String account, + @Param("storeId") String storeId, + @Param("spaceId") String spaceId); } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaSpaceStatsRepo.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaSpaceStatsRepo.java index 7764c3e..96feb19 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaSpaceStatsRepo.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/JpaSpaceStatsRepo.java @@ -17,88 +17,84 @@ import org.springframework.stereotype.Repository; /** - * * @author Daniel Bernstein - * */ -@Repository(value="spaceStatsRepo") +@Repository(value = "spaceStatsRepo") public interface JpaSpaceStatsRepo extends JpaRepository { public static final String INTERVAL_DAY = "%Y-%m-%d"; public static final String INTERVAL_WEEK = "%Y-%u"; public static final String INTERVAL_MONTH = "%Y-%m"; - @Query(nativeQuery=true, - value="select" - + " unix_timestamp(date_format(min(modified), '%Y-%m-%d 00:00:00')) as modified, " - + " account_id," - + " store_id," - + " space_id," - + " avg(byte_count) as byte_count," - + " avg(object_count) as object_count," - + " date_format(modified, :interval) " - + "from space_stats " - + "where account_id = :accountId and " - + " store_id = :storeId and " - + " space_id = :spaceId and " - + " modified between :start and :end " - + "group by date_format(modified, :interval), " - + " account_id, " - + " store_id, " - + " space_id" ) + @Query(nativeQuery = true, + value = "select" + + " unix_timestamp(date_format(min(modified), '%Y-%m-%d 00:00:00')) as modified, " + + " account_id," + + " store_id," + + " space_id," + + " avg(byte_count) as byte_count," + + " avg(object_count) as object_count," + + " date_format(modified, :interval) " + + "from space_stats " + + "where account_id = :accountId and " + + " store_id = :storeId and " + + " space_id = :spaceId and " + + " modified between :start and :end " + + "group by date_format(modified, :interval), " + + " account_id, " + + " store_id, " + + " space_id") public List getByAccountIdAndStoreIdAndSpaceId( - @Param("accountId") String accountId, - @Param("storeId") String storeId, - @Param("spaceId") String spaceId, - @Param("start") Date start, - @Param("end") Date end, - @Param("interval") String interval); + @Param("accountId") String accountId, + @Param("storeId") String storeId, + @Param("spaceId") String spaceId, + @Param("start") Date start, + @Param("end") Date end, + @Param("interval") String interval); - @Query(nativeQuery=true, - value="select a.modified, a.account_id, a.store_id, sum(a.byte_count), sum(a.object_count) from (select" - + " unix_timestamp(date_format(min(modified), '%Y-%m-%d 00:00:00')) as modified, " - + " account_id," - + " store_id," - + " space_id," - + " avg(byte_count) as byte_count," - + " avg(object_count) as object_count," - + " date_format(modified, :interval) " - + "from space_stats " - + "where account_id = :accountId and " - + " store_id = :storeId and " - + " modified between :start and :end " - + "group by date_format(modified, :interval), " - + " account_id, " - + " store_id, " - + " space_id) a " - + "group by a.modified, a.account_id, a.store_id" ) + @Query(nativeQuery = true, + value = "select a.modified, a.account_id, a.store_id, sum(a.byte_count), sum(a.object_count) from (select" + + " unix_timestamp(date_format(min(modified), '%Y-%m-%d 00:00:00')) as modified, " + + " account_id," + + " store_id," + + " space_id," + + " avg(byte_count) as byte_count," + + " avg(object_count) as object_count," + + " date_format(modified, :interval) " + + "from space_stats " + + "where account_id = :accountId and " + + " store_id = :storeId and " + + " modified between :start and :end " + + "group by date_format(modified, :interval), " + + " account_id, " + + " store_id, " + + " space_id) a " + + "group by a.modified, a.account_id, a.store_id") public List getByAccountIdAndStoreId(@Param("accountId") String accountId, - @Param("storeId") String storeId, - @Param("start") Date start, - @Param("end") Date end, - @Param("interval") String interval); + @Param("storeId") String storeId, + @Param("start") Date start, + @Param("end") Date end, + @Param("interval") String interval); - - @Query(nativeQuery=true, - value="select" - + " unix_timestamp(date_format(min(modified), '%Y-%m-%d 00:00:00')) as modified, " - + " account_id," - + " store_id," - + " space_id," - + " avg(byte_count) as byte_count," - + " avg(object_count) as object_count," - + " date_format(modified, '%Y-%m-%d 00:00:00') " - + "from space_stats " - + "where account_id = :accountId and " - + " store_id = :storeId and " - + " modified between :start and :end " - + "group by date_format(modified, '%Y-%m-%d'), " - + " account_id, " - + " store_id, " - + " space_id" ) - public List getByAccountIdAndStoreIdAndDay(@Param("accountId")String accountId, - @Param("storeId")String storeId, - @Param("start")Date start, - @Param("end")Date end); + @Query(nativeQuery = true, + value = "select" + + " unix_timestamp(date_format(min(modified), '%Y-%m-%d 00:00:00')) as modified, " + + " account_id," + + " store_id," + + " space_id," + + " avg(byte_count) as byte_count," + + " avg(object_count) as object_count," + + " date_format(modified, '%Y-%m-%d 00:00:00') " + + "from space_stats " + + "where account_id = :accountId and " + + " store_id = :storeId and " + + " modified between :start and :end " + + "group by date_format(modified, '%Y-%m-%d'), " + + " account_id, " + + " store_id, " + + " space_id") + public List getByAccountIdAndStoreIdAndDay(@Param("accountId") String accountId, + @Param("storeId") String storeId, + @Param("start") Date start, + @Param("end") Date end); - } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/MillJpaRepoConfig.java b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/MillJpaRepoConfig.java index 719a577..0dd4d13 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/MillJpaRepoConfig.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/db/repo/MillJpaRepoConfig.java @@ -9,7 +9,6 @@ import java.text.MessageFormat; import java.util.Properties; - import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; @@ -30,13 +29,11 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; /** - * * @author Daniel Bernstein - * */ @Configuration -@EnableJpaRepositories(basePackages = { "org.duracloud.mill" }, - entityManagerFactoryRef = MillJpaRepoConfig.ENTITY_MANAGER_FACTORY_BEAN, +@EnableJpaRepositories(basePackages = {"org.duracloud.mill"}, + entityManagerFactoryRef = MillJpaRepoConfig.ENTITY_MANAGER_FACTORY_BEAN, transactionManagerRef = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN) @EnableTransactionManagement public class MillJpaRepoConfig { @@ -57,13 +54,13 @@ public BasicDataSource millRepoDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(MessageFormat.format("jdbc:mysql://{0}:{1}/{2}" + - "?useLegacyDatetimeCode=false" + - "&serverTimezone=GMT" + - "&characterEncoding=utf8" + - "&characxterSetResults=utf8", - env.getProperty("mill.db.host", "localhost"), - env.getProperty("mill.db.port", "3306"), - env.getProperty("mill.db.name", "mill"))); + "?useLegacyDatetimeCode=false" + + "&serverTimezone=GMT" + + "&characterEncoding=utf8" + + "&characxterSetResults=utf8", + env.getProperty("mill.db.host", "localhost"), + env.getProperty("mill.db.port", "3306"), + env.getProperty("mill.db.name", "mill"))); dataSource.setUsername(env.getProperty("mill.db.user", "user")); dataSource.setPassword(env.getProperty("mill.db.pass", "pass")); dataSource.setTestOnBorrow(true); @@ -72,9 +69,9 @@ public BasicDataSource millRepoDataSource() { return dataSource; } - @Bean(name=TRANSACTION_MANAGER_BEAN) - public PlatformTransactionManager - millRepoTransactionManager(@Qualifier(MILL_REPO_ENTITY_MANAGER_FACTORY_BEAN) EntityManagerFactory entityManagerFactory) { + @Bean(name = TRANSACTION_MANAGER_BEAN) + public PlatformTransactionManager millRepoTransactionManager( + @Qualifier(MILL_REPO_ENTITY_MANAGER_FACTORY_BEAN) EntityManagerFactory entityManagerFactory) { JpaTransactionManager tm = new JpaTransactionManager(entityManagerFactory); tm.setJpaDialect(new HibernateJpaDialect()); @@ -82,16 +79,16 @@ public BasicDataSource millRepoDataSource() { } @Bean(name = MILL_REPO_ENTITY_MANAGER_FACTORY_BEAN) - public LocalContainerEntityManagerFactoryBean - millRepoEntityManagerFactory(@Qualifier(MILL_REPO_DATA_SOURCE_BEAN) DataSource dataSource) { + public LocalContainerEntityManagerFactoryBean millRepoEntityManagerFactory( + @Qualifier(MILL_REPO_DATA_SOURCE_BEAN) DataSource dataSource) { LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource); emf.setPersistenceUnitName("mill-repo-pu"); emf.setPackagesToScan("org.duracloud.mill"); - JpaConfigurationUtil.configureEntityManagerFactory(env,emf); - if(Boolean.parseBoolean(env.getProperty("generate.database", "false"))){ + JpaConfigurationUtil.configureEntityManagerFactory(env, emf); + if (Boolean.parseBoolean(env.getProperty("generate.database", "false"))) { Properties properties = new Properties(); properties.setProperty("javax.persistence.schema-generation.database.action", "create"); emf.setJpaProperties(properties); @@ -100,7 +97,7 @@ public BasicDataSource millRepoDataSource() { } @Bean - public ManifestStore manifestStore(JpaManifestItemRepo manifestRepo){ - return new JpaManifestStore(manifestRepo); + public ManifestStore manifestStore(JpaManifestItemRepo manifestRepo) { + return new JpaManifestStore(manifestRepo); } } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestItemWriteException.java b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestItemWriteException.java index 7009049..0e570ad 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestItemWriteException.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestItemWriteException.java @@ -7,10 +7,9 @@ */ package org.duracloud.mill.manifest; - /** * @author Daniel Bernstein - * Date: Sep 2, 2014 + * Date: Sep 2, 2014 */ public class ManifestItemWriteException extends Exception { /** @@ -18,7 +17,7 @@ public class ManifestItemWriteException extends Exception { * @param ex */ public ManifestItemWriteException(String message, Exception ex) { - super(message,ex); + super(message, ex); } - + } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestStore.java b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestStore.java index 5811377..a7d1a68 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestStore.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/ManifestStore.java @@ -13,10 +13,9 @@ import org.duracloud.common.db.error.NotFoundException; import org.duracloud.mill.db.model.ManifestItem; - /** * @author Daniel Bernstein - * Date: Sep 2, 2014 + * Date: Sep 2, 2014 */ public interface ManifestStore { @@ -26,20 +25,20 @@ public interface ManifestStore { * @param spaceId * @param contentId * @param contentChecksum - * @param contentSize - * @param contentMimetype - * @param timeStamp - * @throws ManifestItemWriteException + * @param contentSize + * @param contentMimetype + * @param timeStamp * @return true if the store was updated; false if it was not (due to the update being out of order). + * @throws ManifestItemWriteException */ public boolean addUpdate(String account, - String storeId, - String spaceId, - String contentId, - String contentChecksum, - String contentMimetype, - String contentSize, - Date timeStamp) throws ManifestItemWriteException; + String storeId, + String spaceId, + String contentId, + String contentChecksum, + String contentMimetype, + String contentSize, + Date timeStamp) throws ManifestItemWriteException; /** * @param storeId @@ -52,6 +51,7 @@ public Iterator getItems(String account, /** * Provides a method or ordering the results + * * @param account * @param storeId * @param spaceId @@ -64,7 +64,6 @@ public Iterator getItems(String account, boolean ordered); /** - * * @param account * @param storeId * @param spaceId @@ -73,9 +72,9 @@ public Iterator getItems(String account, * @throws NotFoundException */ public ManifestItem getItem(String account, - String storeId, - String spaceId, - String contentId) throws NotFoundException; + String storeId, + String spaceId, + String contentId) throws NotFoundException; /** * @param account @@ -83,39 +82,36 @@ public ManifestItem getItem(String account, * @param spaceId * @param contentId * @param eventTimestamp - * @throws ManifestItemWriteException * @return true if the store was updated; false if it was not (due to the update being out of order). + * @throws ManifestItemWriteException */ public boolean flagAsDeleted(String account, - String storeId, - String spaceId, - String contentId, - Date eventTimestamp) throws ManifestItemWriteException; - + String storeId, + String spaceId, + String contentId, + Date eventTimestamp) throws ManifestItemWriteException; + /** - * * @param expiration * @return Count of items deleted. */ public int purgeDeletedItemsBefore(Date expiration); /** - * * @param account * @param storeId * @param spaceId * @param contentId * @param flag - * @throws ManifestItemWriteException + * @throws ManifestItemWriteException */ public void updateMissingFromStorageProviderFlag(String account, - String storeId, - String spaceId, - String contentId, - boolean flag) throws ManifestItemWriteException; + String storeId, + String spaceId, + String contentId, + boolean flag) throws ManifestItemWriteException; /** - * * @param account * @param storeId * @param spaceId diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/JpaManifestStore.java b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/JpaManifestStore.java index a031a01..12589d8 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/JpaManifestStore.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/JpaManifestStore.java @@ -28,12 +28,9 @@ import org.springframework.transaction.annotation.Transactional; /** - * * @author Daniel Bernstein - * */ -public class JpaManifestStore implements - ManifestStore { +public class JpaManifestStore implements ManifestStore { private static Logger log = LoggerFactory.getLogger(JpaManifestStore.class); private JpaManifestItemRepo manifestItemRepo; @@ -45,71 +42,68 @@ public JpaManifestStore(JpaManifestItemRepo manifestItemRepo) { @Override @Transactional(value = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN, propagation = Propagation.REQUIRES_NEW) public boolean addUpdate(String account, - String storeId, - String spaceId, - String contentId, - String contentChecksum, - String contentMimetype, - String contentSize, - Date eventTimestamp) throws ManifestItemWriteException { - - if(log.isDebugEnabled()){ + String storeId, + String spaceId, + String contentId, + String contentChecksum, + String contentMimetype, + String contentSize, + Date eventTimestamp) throws ManifestItemWriteException { + + if (log.isDebugEnabled()) { log.debug("preparing to write account={}, " + - "storeId={}, " + - "spaceId={}, " + - "contentId={}, " + - "contentChecksum={}, " + - "contentMimetype={}, " + - "contentSize={}, " + - "eventTimestamp={}", - account, - storeId, - spaceId, - contentId, - contentChecksum, - contentMimetype, - contentSize, - eventTimestamp); + "storeId={}, " + + "spaceId={}, " + + "contentId={}, " + + "contentChecksum={}, " + + "contentMimetype={}, " + + "contentSize={}, " + + "eventTimestamp={}", + account, + storeId, + spaceId, + contentId, + contentChecksum, + contentMimetype, + contentSize, + eventTimestamp); } - + try { - + boolean save = false; - + ManifestItem item = this.manifestItemRepo - .findByAccountAndStoreIdAndSpaceIdAndContentId(account, - storeId, - spaceId, - contentId); + .findByAccountAndStoreIdAndSpaceIdAndContentId(account, storeId, spaceId, contentId); String action = "added"; - - if(item != null){ - if(eventOutOfOrder(item, eventTimestamp)){ + + if (item != null) { + if (eventOutOfOrder(item, eventTimestamp)) { return false; } //flip deleted flag if set to deleted - if(item.isDeleted()){ + if (item.isDeleted()) { item.setDeleted(false); } String oldChecksum = item.getContentChecksum(); - if(!oldChecksum.equals(contentChecksum)){ + if (!oldChecksum.equals(contentChecksum)) { log.info("content checksum changed from {} to {}", oldChecksum, contentChecksum); } String oldMimetype = item.getContentMimetype(); - if(!oldMimetype.equals(contentMimetype)){ + if (!oldMimetype.equals(contentMimetype)) { log.info("content mimetype changed from {} to {}", oldMimetype, contentMimetype); } String oldSize = item.getContentSize(); - if(!oldSize.equals(contentSize)){ + if (!oldSize.equals(contentSize)) { log.info("content size changed from {} to {}", oldMimetype, contentSize); } action = "updated"; - }else{ + } else { item = new ManifestItem(); item.setAccount(account); item.setStoreId(storeId); @@ -130,47 +124,48 @@ public boolean addUpdate(String account, throw new ManifestItemWriteException(message, ex); } } - + /* (non-Javadoc) - * @see org.duracloud.mill.manifest.ManifestStore#flagAsDeleted(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + * @see org.duracloud.mill.manifest.ManifestStore#flagAsDeleted(java.lang.String, java.lang.String, java.lang + * .String, java.lang.String) */ @Override @Transactional(value = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN, propagation = Propagation.REQUIRES_NEW) public boolean flagAsDeleted(String account, - String storeId, - String spaceId, - String contentId, - Date eventTimestamp) throws ManifestItemWriteException { + String storeId, + String spaceId, + String contentId, + Date eventTimestamp) throws ManifestItemWriteException { try { - + ManifestItem item = this.manifestItemRepo - .findByAccountAndStoreIdAndSpaceIdAndContentId(account, - storeId, - spaceId, - contentId); - - if(item != null){ - if(eventOutOfOrder(item, eventTimestamp)){ + .findByAccountAndStoreIdAndSpaceIdAndContentId(account, + storeId, + spaceId, + contentId); + + if (item != null) { + if (eventOutOfOrder(item, eventTimestamp)) { return false; } - - if(item.isDeleted()){ + + if (item.isDeleted()) { log.warn("item {}/{}/{}/{} has already been deleted - " + - "there appears to have been a duplicate event " + - "or possibly a missed content add event - ignoring...", + "there appears to have been a duplicate event " + + "or possibly a missed content add event - ignoring...", account, storeId, spaceId, contentId); - + } - }else{ - log.warn("no manifest item {}/{}/{}/{} : nothing to delete - adding deleted manifest entry...", - account, - storeId, - spaceId, - contentId); - + } else { + log.warn("no manifest item {}/{}/{}/{} : nothing to delete - adding deleted manifest entry...", + account, + storeId, + spaceId, + contentId); + item = new ManifestItem(); item.setAccount(account); item.setStoreId(storeId); @@ -190,7 +185,7 @@ public boolean flagAsDeleted(String account, String message = "failed to flag item as deleted item: " + ex.getMessage(); log.error(message); throw new ManifestItemWriteException(message, ex); - } + } } /** @@ -201,16 +196,16 @@ public boolean flagAsDeleted(String account, private boolean eventOutOfOrder(ManifestItem item, Date eventTimestamp) { long itemTime = item.getModified().getTime(); long eventTime = eventTimestamp.getTime(); - - if(eventTime < itemTime){ + + if (eventTime < itemTime) { log.warn("The current database item is more " + "current that the event: item last modified: " + "{}, event timestamp: {}. Likely cause: events " + - "were delivered out of order. Ignoring...", - itemTime, + "were delivered out of order. Ignoring...", + itemTime, eventTime); return true; - }else{ + } else { return false; } } @@ -221,87 +216,84 @@ public Iterator getItems(final String account, final String spaceId) { return getItems(account, storeId, spaceId, false); } - + @Override public Iterator getItems(final String account, final String storeId, - final String spaceId, - final boolean ordered) { - - if(ordered){ - return getItemsOrdered(account, storeId, spaceId); - }else{ - return getItemsUnordered(account,storeId, spaceId); - } + final String spaceId, + final boolean ordered) { + if (ordered) { + return getItemsOrdered(account, storeId, spaceId); + } else { + return getItemsUnordered(account, storeId, spaceId); + } + + } + + private Iterator getItemsOrdered(final String account, final String storeId, final String spaceId) { + JpaIteratorSource source = + new JpaIteratorSource(this.manifestItemRepo, 10000) { + @Override + protected Page getNextPage(Pageable pageable, + JpaManifestItemRepo repo) { + return manifestItemRepo + .findByAccountAndStoreIdAndSpaceIdAndDeletedFalseOrderByContentIdAsc(account, + storeId, + spaceId, + pageable); + } + }; + return (Iterator) new StreamingIterator(source); } - private Iterator getItemsOrdered(final String account, final String storeId, final String spaceId) { - JpaIteratorSource source = - new JpaIteratorSource(this.manifestItemRepo, 10000) { - @Override - protected Page getNextPage(Pageable pageable, - JpaManifestItemRepo repo) { - - return manifestItemRepo - .findByAccountAndStoreIdAndSpaceIdAndDeletedFalseOrderByContentIdAsc(account, - storeId, - spaceId, - pageable); - } - }; - return (Iterator) new StreamingIterator(source); - } - - /** - * - * @param account - * @param storeId - * @param spaceId - * @return - */ + /** + * @param account + * @param storeId + * @param spaceId + * @return + */ private Iterator getItemsUnordered(final String account, - final String storeId, - final String spaceId) { - return new StreamingIterator( - new ManifestItemIteratorSource(this.manifestItemRepo, - account, - storeId, - spaceId, - 10000)); + final String storeId, + final String spaceId) { + return new StreamingIterator( + new ManifestItemIteratorSource(this.manifestItemRepo, + account, + storeId, + spaceId, + 10000)); } - + @Override - public ManifestItem - getItem(final String account, - final String storeId, - final String spaceId, - final String contentId) throws NotFoundException { + public ManifestItem getItem(final String account, + final String storeId, + final String spaceId, + final String contentId) throws NotFoundException { ManifestItem item = this.manifestItemRepo - .findByAccountAndStoreIdAndSpaceIdAndContentId(account, - storeId, - spaceId, - contentId); + .findByAccountAndStoreIdAndSpaceIdAndContentId(account, + storeId, + spaceId, + contentId); if (item == null) { - throw new NotFoundException(MessageFormat.format("No ManifestItem could be found matching the specified params: " + - "account={0}, storeId={1}, spaceId={2}, contentId={3}", - account, - storeId, - spaceId, - contentId)); + throw new NotFoundException( + MessageFormat.format("No ManifestItem could be found matching the specified params: " + + "account={0}, storeId={1}, spaceId={2}, contentId={3}", + account, + storeId, + spaceId, + contentId)); } return item; } - /* (non-Javadoc) * @see org.duracloud.mill.manifest.ManifestStore#purgeDeletedItemsBefore(java.util.Date) */ @Override @Transactional(value = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN, propagation = Propagation.REQUIRES_NEW) public int purgeDeletedItemsBefore(Date expiration) { - return this.manifestItemRepo.deleteFirst50000ByDeletedTrueAndModifiedBefore(expiration); + return this.manifestItemRepo.deleteFirst50000ByDeletedTrueAndModifiedBefore(expiration); } @Override @@ -311,27 +303,25 @@ public void updateMissingFromStorageProviderFlag(String account, String spaceId, String contentId, boolean flag) throws ManifestItemWriteException { - + try { - + ManifestItem item = this.manifestItemRepo - .findByAccountAndStoreIdAndSpaceIdAndContentId(account, - storeId, - spaceId, - contentId); - - if(item != null){ - + .findByAccountAndStoreIdAndSpaceIdAndContentId(account, + storeId, + spaceId, + contentId); + + if (item != null) { item.setMissingFromStorageProvider(flag); ManifestItem result = this.manifestItemRepo.saveAndFlush(item); log.info("successfully processed update MissingFromStorageProvider flag: {}", result); - - }else{ - String message = MessageFormat.format("no manifest item found: {0}/{1}/{2}/{3}: something's amiss.", - account, - storeId, - spaceId, - contentId); + } else { + String message = MessageFormat.format("no manifest item found: {0}/{1}/{2}/{3}: something's amiss.", + account, + storeId, + spaceId, + contentId); throw new NotFoundException(message); } @@ -339,14 +329,14 @@ public void updateMissingFromStorageProviderFlag(String account, String message = "failed to update manifest item with : " + ex.getMessage(); log.error(message); throw new ManifestItemWriteException(message, ex); - } + } } @Override @Transactional(value = MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN, propagation = Propagation.REQUIRES_NEW) public void delete(String account, String storeId, String spaceId) throws ManifestItemWriteException { - this.manifestItemRepo.deleteByAccountAndStoreIdAndSpaceId(account,storeId, spaceId); + this.manifestItemRepo.deleteByAccountAndStoreIdAndSpaceId(account, storeId, spaceId); } } diff --git a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/ManifestItemIteratorSource.java b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/ManifestItemIteratorSource.java index 59aec2b..f3f347a 100644 --- a/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/ManifestItemIteratorSource.java +++ b/mill-db-repo/src/main/java/org/duracloud/mill/manifest/jpa/ManifestItemIteratorSource.java @@ -16,46 +16,45 @@ import org.springframework.util.CollectionUtils; /** - * * @author Daniel Bernstein - * */ -public class ManifestItemIteratorSource implements IteratorSource{ - - private JpaManifestItemRepo repo; - - private Long markerId = null; - private String account; - private String spaceId; - private String storeId; - private int pageSize; - - public ManifestItemIteratorSource(JpaManifestItemRepo repo, String account, String storeId, String spaceId, int pageSize) { - this.repo = repo; - this.account = account; - this.storeId = storeId; - this.spaceId = spaceId; - this.pageSize = pageSize; - } - - @Override - public Collection getNext() { - if(markerId == null){ - markerId = this.repo.getMinId(this.account, this.storeId, this.spaceId)-1; - } - - assert markerId != null; - - List items = this.repo.findByAccountAndStoreIdAndSpaceIdAndDeletedFalse(account, storeId, spaceId, - markerId, pageSize); - - if(!CollectionUtils.isEmpty(items)){ - this.markerId = items.get(items.size()-1).getId(); - return items; - }else{ - return null; - } - } +public class ManifestItemIteratorSource implements IteratorSource { + + private JpaManifestItemRepo repo; + + private Long markerId = null; + private String account; + private String spaceId; + private String storeId; + private int pageSize; + + public ManifestItemIteratorSource(JpaManifestItemRepo repo, String account, String storeId, String spaceId, + int pageSize) { + this.repo = repo; + this.account = account; + this.storeId = storeId; + this.spaceId = spaceId; + this.pageSize = pageSize; + } + + @Override + public Collection getNext() { + if (markerId == null) { + markerId = this.repo.getMinId(this.account, this.storeId, this.spaceId) - 1; + } + + assert markerId != null; + + List items = this.repo.findByAccountAndStoreIdAndSpaceIdAndDeletedFalse(account, storeId, spaceId, + markerId, pageSize); + + if (!CollectionUtils.isEmpty(items)) { + this.markerId = items.get(items.size() - 1).getId(); + return items; + } else { + return null; + } + } } diff --git a/mill-db-repo/src/test/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStoreTest.java b/mill-db-repo/src/test/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStoreTest.java index ebb295b..6a34aa7 100644 --- a/mill-db-repo/src/test/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStoreTest.java +++ b/mill-db-repo/src/test/java/org/duracloud/mill/auditor/jpa/JpaAuditLogStoreTest.java @@ -18,9 +18,9 @@ import java.util.Date; import java.util.Iterator; +import org.duracloud.common.db.error.NotFoundException; import org.duracloud.mill.auditor.AuditLogItem; import org.duracloud.mill.auditor.AuditLogWriteFailedException; -import org.duracloud.common.db.error.NotFoundException; import org.duracloud.mill.db.model.JpaAuditLogItem; import org.duracloud.mill.db.repo.JpaAuditLogItemRepo; import org.duracloud.mill.test.jpa.JpaTestBase; @@ -32,47 +32,48 @@ /** * @author Daniel Bernstein - * Date: Aug 29, 2014 + * Date: Aug 29, 2014 */ -public class JpaAuditLogStoreTest extends JpaTestBase{ +public class JpaAuditLogStoreTest extends JpaTestBase { private JpaAuditLogStore auditLogStore; - + @Mock private JpaAuditLogItemRepo repo; - + private String account = "account"; private String storeId = "store-id"; private String spaceId = "space-id"; - private String contentId= "content-id"; - private String contentMd5= "content-md5"; + private String contentId = "content-id"; + private String contentMd5 = "content-md5"; private String mimetype = "mime-type"; private String contentSize = "content-size"; private String user = "user"; private String action = "action"; - private String properties= "{}"; - private String spaceAcls= "{}"; + private String properties = "{}"; + private String spaceAcls = "{}"; private String sourceSpaceId = "source-space-id"; private String sourceContentId = "source-content-id"; private Date timestamp = new Date(); - + /** * Test method for - * {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#write(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Date)} + * {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#write(java.lang.String, java.lang.String, java.lang + * .String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang + * .String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Date)} * . - * @throws AuditLogWriteFailedException + * + * @throws AuditLogWriteFailedException */ @Test public void testWrite() throws AuditLogWriteFailedException { Capture jpaItemCapture = new Capture<>(); - expect(repo.saveAndFlush(capture(jpaItemCapture))) - .andReturn(new JpaAuditLogItem()); - - replayAll(); + .andReturn(new JpaAuditLogItem()); + replayAll(); this.auditLogStore = new JpaAuditLogStore(repo); @@ -90,9 +91,9 @@ public void testWrite() throws AuditLogWriteFailedException { sourceSpaceId, sourceContentId, timestamp); - + JpaAuditLogItem item = jpaItemCapture.getValue(); - + assertEquals(item.getAccount(), account); assertEquals(item.getSpaceId(), spaceId); assertEquals(item.getContentId(), contentId); @@ -103,14 +104,15 @@ public void testWrite() throws AuditLogWriteFailedException { assertEquals(item.getAction(), action); assertEquals(item.getContentProperties(), properties); assertEquals(item.getSpaceAcls(), spaceAcls); - assertEquals(item.getSourceSpaceId(),sourceSpaceId); + assertEquals(item.getSourceSpaceId(), sourceSpaceId); assertEquals(item.getSourceContentId(), sourceContentId); assertEquals(item.getTimestamp(), timestamp.getTime()); } /** - * Test method for {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#getLogItems(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. + * Test method for + * {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#getLogItems(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. */ @Test public void testGetLogItemsByAccountStoreIdSpaceIdAndContentId() { @@ -119,45 +121,47 @@ public void testGetLogItemsByAccountStoreIdSpaceIdAndContentId() { int count = 10; Page page = setupPage(count); - expect(this.repo - .findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByContentIdAsc(eq(account), - eq(storeId), - eq(spaceId), - eq(contentId), - capture(capture))) - .andReturn(page); + expect(this.repo.findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByContentIdAsc(eq(account), + eq(storeId), + eq(spaceId), + eq(contentId), + capture(capture))) + .andReturn(page); replayAll(); Iterator it = this.auditLogStore.getLogItems(account, - storeId, - spaceId, - contentId); + storeId, + spaceId, + contentId); verifyIterator(count, it); verifyPageable(capture); } /** - * Test method for {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#getLatestLogItem(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. - * @throws NotFoundException + * Test method for + * {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#getLatestLogItem(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. + * + * @throws NotFoundException */ @Test public void testGetLatestLogItem() throws NotFoundException { this.auditLogStore = new JpaAuditLogStore(repo); - expect(repo - .findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByTimestampDesc(account, - storeId, - spaceId, - contentId)) - .andReturn(Arrays.asList(new JpaAuditLogItem[] { new JpaAuditLogItem() })); + expect(repo.findByAccountAndStoreIdAndSpaceIdAndContentIdOrderByTimestampDesc(account, + storeId, + spaceId, + contentId)) + .andReturn(Arrays.asList(new JpaAuditLogItem[] {new JpaAuditLogItem()})); replayAll(); AuditLogItem item = this.auditLogStore.getLatestLogItem(account, storeId, spaceId, contentId); assertNotNull(item); - + } /** - * Test method for {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#updateProperties(org.duracloud.audit.AuditLogItem, java.lang.String)}. - * @throws AuditLogWriteFailedException + * Test method for + * {@link org.duracloud.mill.auditor.jpa.JpaAuditLogStore#updateProperties(org.duracloud.mill.auditor.AuditLogItem, java.lang.String)}. + * + * @throws AuditLogWriteFailedException */ @Test public void testUpdateProperties() throws AuditLogWriteFailedException { @@ -166,18 +170,16 @@ public void testUpdateProperties() throws AuditLogWriteFailedException { Long id = 100l; item.setId(id); String serializedProps = "{}"; - + JpaAuditLogItem freshItem = createMock(JpaAuditLogItem.class); expect(repo.findOne(eq(id))).andReturn(freshItem); freshItem.setContentProperties(serializedProps); expectLastCall().once(); expect(repo.saveAndFlush(freshItem)).andReturn(freshItem); replayAll(); - + this.auditLogStore.updateProperties(item, serializedProps); - - - + } /* (non-Javadoc) diff --git a/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/JpaManifestStoreTest.java b/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/JpaManifestStoreTest.java index 4538c81..0108bfe 100644 --- a/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/JpaManifestStoreTest.java +++ b/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/JpaManifestStoreTest.java @@ -28,7 +28,6 @@ import org.easymock.Mock; import org.junit.Assert; import org.junit.Test; -import org.springframework.data.domain.Pageable; /** * @author Daniel Bernstein Date: Sep 2, 2014 @@ -51,7 +50,7 @@ public class JpaManifestStoreTest extends JpaTestBase { * Test method for * {@link org.duracloud.mill.manifest.jpa.JpaManifestStore#add(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)} * . - * + * * @throws ManifestItemWriteException */ @Test @@ -67,13 +66,13 @@ public void testAdd() throws ManifestItemWriteException { replayAll(); Date timestamp = new Date(); assertTrue(store.addUpdate(account, - storeId, - spaceId, - contentId, - contentChecksum, - contentMimetype, - contentSize, - timestamp)); + storeId, + spaceId, + contentId, + contentChecksum, + contentMimetype, + contentSize, + timestamp)); ManifestItem item = capture.getValue(); assertEquals(account, item.getAccount()); assertEquals(storeId, item.getStoreId()); @@ -92,7 +91,7 @@ public void testUpdate() throws ManifestItemWriteException { Date timestamp = new Date(); ManifestItem returnItem = createMock(ManifestItem.class); expect(returnItem.getModified()).andReturn(new Date(System.currentTimeMillis() - 1000)); - + expect(returnItem.getContentChecksum()).andReturn("old checksum"); returnItem.setContentChecksum(contentChecksum); expectLastCall().once(); @@ -118,22 +117,21 @@ public void testUpdate() throws ManifestItemWriteException { expect(repo.saveAndFlush(returnItem)).andReturn(returnItem); replayAll(); assertTrue(store.addUpdate(account, - storeId, - spaceId, - contentId, - contentChecksum, - contentMimetype, - contentSize, - timestamp)); + storeId, + spaceId, + contentId, + contentChecksum, + contentMimetype, + contentSize, + timestamp)); } - - + @Test public void testIgnoreUpdateDueToOutOfOrderMessage() throws ManifestItemWriteException { createTestSubject(); ManifestItem returnItem = createMock(ManifestItem.class); Date present = new Date(System.currentTimeMillis()); - Date past = new Date(present.getTime()-1); + Date past = new Date(present.getTime() - 1); expect(returnItem.getModified()).andReturn(present); expect(this.repo.findByAccountAndStoreIdAndSpaceIdAndContentId(account, @@ -143,13 +141,13 @@ public void testIgnoreUpdateDueToOutOfOrderMessage() throws ManifestItemWriteExc replayAll(); assertFalse(store.addUpdate(account, - storeId, - spaceId, - contentId, - contentChecksum, - contentMimetype, - contentSize, - past)); + storeId, + spaceId, + contentId, + contentChecksum, + contentMimetype, + contentSize, + past)); } @Test @@ -181,15 +179,15 @@ public void testFlagAsNotFound() throws ManifestItemWriteException { storeId, spaceId, contentId)).andReturn(null); - Capture itemCapture = new Capture(); - + Capture itemCapture = new Capture(); + expect(repo.saveAndFlush(capture(itemCapture))).andReturn(new ManifestItem()); - + replayAll(); assertTrue(store.flagAsDeleted(account, storeId, spaceId, contentId, timestamp)); - + ManifestItem item = itemCapture.getValue(); - + assertNotNull(item.getContentChecksum()); assertNotNull(item.getContentMimetype()); assertNotNull(item.getContentSize()); @@ -205,7 +203,6 @@ private void createTestSubject() { store = new JpaManifestStore(repo); } - @Test public void updateMissingFromStorageProviderFlag() throws ManifestItemWriteException { createTestSubject(); @@ -226,9 +223,9 @@ public void updateMissingFromStorageProviderFlag() throws ManifestItemWriteExcep } @Test - public void updateMissingFromStorageProviderFlagNotFound() { + public void updateMissingFromStorageProviderFlagNotFound() { createTestSubject(); - + expect(this.repo.findByAccountAndStoreIdAndSpaceIdAndContentId(account, storeId, spaceId, @@ -243,6 +240,7 @@ public void updateMissingFromStorageProviderFlagNotFound() { true); Assert.fail("expected failure"); } catch (ManifestItemWriteException e) { + // Expected exception } } @@ -258,24 +256,24 @@ public void testGetItems() { int count = 10; List list = setupList(count); - expect(list.get(count-1).getId()).andReturn((long)count); - + expect(list.get(count - 1).getId()).andReturn((long) count); + expect(this.repo.getMinId(eq(account), eq(storeId), eq(spaceId))).andReturn(1l); - + expect(this.repo.findByAccountAndStoreIdAndSpaceIdAndDeletedFalse(eq(account), - eq(storeId), - eq(spaceId), - eq(0l),eq(10000))).andReturn(list); + eq(storeId), + eq(spaceId), + eq(0l), eq(10000))).andReturn(list); expect(this.repo.findByAccountAndStoreIdAndSpaceIdAndDeletedFalse(eq(account), - eq(storeId), - eq(spaceId), - eq(10l), - eq(10000))).andReturn(null); + eq(storeId), + eq(spaceId), + eq(10l), + eq(10000))).andReturn(null); replayAll(); - Iterator it = this.store.getItems(account,storeId, spaceId); + Iterator it = this.store.getItems(account, storeId, spaceId); verifyIterator(count, it); } @@ -298,7 +296,7 @@ public void testGetItem() throws Exception { /* * (non-Javadoc) - * + * * @see org.duracloud.mill.test.jpa.JpaTestBase#create() */ @Override diff --git a/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ManifestStoreIntegrationTest.java b/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ManifestStoreIntegrationTest.java index 656b9d8..ca6a2ce 100644 --- a/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ManifestStoreIntegrationTest.java +++ b/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ManifestStoreIntegrationTest.java @@ -24,10 +24,11 @@ /** * This test class runs tests against a live embedded mysql database. * While the JpaManifestStoreTest covers similar territory, we uncovered - * some bugs connected to underlying JPA storage mechanisms. This class - * was added to verify that the code works against a running database. - * @author Daniel Bernstein - * Date: June 8, 2017 + * some bugs connected to underlying JPA storage mechanisms. This class + * was added to verify that the code works against a running database. + * + * @author Daniel Bernstein + * Date: June 8, 2017 */ public class ManifestStoreIntegrationTest extends JpaIntegrationTestBase { @@ -63,8 +64,7 @@ public void testAdd() throws Exception { private ManifestItem addAndRetrieveItem(Date timestamp) throws ManifestItemWriteException, NotFoundException { ManifestStore store = getStore(); assertTrue(store.addUpdate(account, storeId, spaceId, contentId, contentChecksum, contentMimetype, - contentSize, - timestamp)); + contentSize, timestamp)); ManifestItem item = store.getItem(account, storeId, spaceId, contentId); return item; } @@ -86,8 +86,7 @@ public void testUpdate() throws Exception { long ms999ago = oneSecondAgo + 1; assertTrue(store.addUpdate(account, storeId, spaceId, contentId, contentChecksum2, contentMimetype2, - contentSize2, - new Date(ms999ago))); + contentSize2, new Date(ms999ago))); // get it ManifestItem item2 = store.getItem(account, storeId, spaceId, contentId); @@ -115,8 +114,7 @@ public void testIgnoreUpdateDueToOutOfOrderMessage() throws Exception { long pastTime = currentTime - 1; String newChecksum = "checksum-2"; assertFalse(store.addUpdate(account, storeId, spaceId, contentId, newChecksum, contentMimetype, - contentSize, - new Date(pastTime))); + contentSize, new Date(pastTime))); // get it ManifestItem item2 = store.getItem(account, storeId, spaceId, contentId); diff --git a/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ModelIntegrationTest.java b/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ModelIntegrationTest.java index 0bcb24f..6a585ed 100644 --- a/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ModelIntegrationTest.java +++ b/mill-db-repo/src/test/java/org/duracloud/mill/manifest/jpa/ModelIntegrationTest.java @@ -20,8 +20,9 @@ /** * This test class runs tests against a live embedded mysql database. - * @author Daniel Bernstein - * Date: August 23, 2017 + * + * @author Daniel Bernstein + * Date: August 23, 2017 */ public class ModelIntegrationTest extends JpaIntegrationTestBase { @@ -33,13 +34,12 @@ public class ModelIntegrationTest extends JpaIntegrationTestBase { private String contentId = "content-id"; - @Test public void testAddBitReport() throws Exception { long oneSecondAgo = System.currentTimeMillis() - 1000; Date timestamp = new Date(oneSecondAgo); BitIntegrityReport report = new BitIntegrityReport(); - + report.setAccount(account); report.setCompletionDate(timestamp); report.setModified(timestamp); @@ -47,7 +47,7 @@ public void testAddBitReport() throws Exception { report.setReportSpaceId(spaceId); report.setSpaceId(spaceId); report.setStoreId(storeId); - + report = getRepo().saveAndFlush(report); assertEquals(account, report.getAccount()); assertEquals(storeId, report.getStoreId()); @@ -60,9 +60,6 @@ public void testAddBitReport() throws Exception { assertEquals(timestamp, report.getModified()); } - - - private JpaBitIntegrityReportRepo getRepo() { return context.getBean(JpaBitIntegrityReportRepo.class); } diff --git a/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaIntegrationTestBase.java b/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaIntegrationTestBase.java index e1657b4..601ab6c 100644 --- a/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaIntegrationTestBase.java +++ b/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaIntegrationTestBase.java @@ -15,6 +15,9 @@ import java.util.concurrent.TimeUnit; +import com.wix.mysql.EmbeddedMysql; +import com.wix.mysql.ScriptResolver; +import com.wix.mysql.config.MysqldConfig; import org.easymock.EasyMockRunner; import org.easymock.EasyMockSupport; import org.junit.After; @@ -22,13 +25,9 @@ import org.junit.runner.RunWith; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import com.wix.mysql.EmbeddedMysql; -import com.wix.mysql.ScriptResolver; -import com.wix.mysql.config.MysqldConfig; - /** - * @author Daniel Bernstein - * Date: June 8, 2017 + * @author Daniel Bernstein + * Date: June 8, 2017 */ @RunWith(EasyMockRunner.class) public abstract class JpaIntegrationTestBase extends EasyMockSupport { @@ -41,14 +40,15 @@ public abstract class JpaIntegrationTestBase extends EasyMockSupport { public void setup() { int port = 3310; MysqldConfig config = aMysqldConfig(v5_6_latest).withCharset(UTF8).withPort(3306).withUser("user", "pass") - .withTimeZone("GMT").withTimeout(2, TimeUnit.MINUTES).withServerVariable("max_connect_errors", 666) - .withPort(port) - .build(); + .withTimeZone("GMT").withTimeout(2, TimeUnit.MINUTES) + .withServerVariable("max_connect_errors", 666) + .withPort(port) + .build(); mysqld = anEmbeddedMysql(config).addSchema("mill", ScriptResolver.classPathScript("db_init.sql")).start(); System.setProperty("generate.database", "true"); - System.setProperty("mill.db.port", port+""); + System.setProperty("mill.db.port", port + ""); context = new AnnotationConfigApplicationContext("org.duracloud.mill"); diff --git a/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaTestBase.java b/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaTestBase.java index 9ea6a91..a74c9e8 100644 --- a/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaTestBase.java +++ b/mill-db-repo/src/test/java/org/duracloud/mill/test/jpa/JpaTestBase.java @@ -25,46 +25,46 @@ /** * @author Daniel Bernstein - * Date: Sep 3, 2014 + * Date: Sep 3, 2014 */ @RunWith(EasyMockRunner.class) public abstract class JpaTestBase extends EasyMockSupport { @After - public void tearDown(){ + public void tearDown() { verifyAll(); } protected void verifyPageable(Capture capture) { Pageable pageable = capture.getValue(); assertNotNull(pageable); - assertEquals(0,pageable.getPageNumber()); + assertEquals(0, pageable.getPageNumber()); } protected void verifyIterator(int count, Iterator it) { int recount = 0; - while(it.hasNext()){ + while (it.hasNext()) { it.next(); recount++; } assertEquals(count, recount); } - + protected Page setupPage(int count) { Page page = createMock(Page.class); - - List items = setupList(count); + + List items = setupList(count); expect(page.getContent()).andReturn(items); expect(page.getTotalPages()).andReturn(1); return page; } protected List setupList(int count) { - List items = new ArrayList<>(); - for(int i = 0; i < count; i++){ + List items = new ArrayList<>(); + for (int i = 0; i < count; i++) { items.add(create()); } - + return items; } diff --git a/mill-db-repo/src/test/resources/logback.xml b/mill-db-repo/src/test/resources/logback.xml index 75f2db5..abfed40 100644 --- a/mill-db-repo/src/test/resources/logback.xml +++ b/mill-db-repo/src/test/resources/logback.xml @@ -1,10 +1,10 @@ - + - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - + + + + diff --git a/pom.xml b/pom.xml index ee68824..5ff2163 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.duracloud.db @@ -46,9 +46,9 @@ - scm:git:git@github.com:duracloud/duracloud-db.git - scm:git:git@github.com:duracloud/duracloud-db.git - scm:git:git@github.com:duracloud/duracloud-db.git + scm:git:git@github.com:duracloud/duracloud-db.git + scm:git:git@github.com:duracloud/duracloud-db.git + scm:git:git@github.com:duracloud/duracloud-db.git @@ -85,66 +85,66 @@ - profile-generate-docs-source-signature - - false - - releaseBuild - - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.3 - - - attach-sources - verify - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - verify - - jar - - - ${javadoc.opts} - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - - + profile-generate-docs-source-signature + + false + + releaseBuild + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.3 + + + attach-sources + verify + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + verify + + jar + + + ${javadoc.opts} + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + @@ -256,16 +256,13 @@ - + ${mainClass} - + META-INF/spring.handlers - + META-INF/spring.schemas @@ -273,7 +270,7 @@ - + maven-dependency-plugin 2.8 @@ -356,7 +353,7 @@ - + true @@ -385,6 +382,45 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.0.0 + + + verify-style + + process-classes + + check + + + + + + https://raw.githubusercontent.com/duraspace/resources/master/checkstyle/duraspace-checkstyle.xml + + + https://raw.githubusercontent.com/duraspace/resources/master/checkstyle/duraspace-checkstyle-suppressions.xml + + UTF-8 + true + true + true + true + + + + + com.puppycrawl.tools + checkstyle + 8.8 + + + + @@ -450,7 +486,7 @@ org.apache.commons commons-dbcp2 - 2.1 + 2.1 commons-logging @@ -458,12 +494,12 @@ - + - commons-codec - commons-codec - 1.9 - + commons-codec + commons-codec + 1.9 + org.springframework @@ -500,12 +536,12 @@ - + - org.springframework.security - spring-security-core - ${org.springframework.security.version} - + org.springframework.security + spring-security-core + ${org.springframework.security.version} + org.springframework.data @@ -526,15 +562,15 @@ - org.springframework - spring-tx - ${org.springframework.version} - - - commons-logging - commons-logging - - + org.springframework + spring-tx + ${org.springframework.version} + + + commons-logging + commons-logging + + @@ -552,8 +588,8 @@ org.hibernate hibernate-validator - ${hibernate.version} - + ${hibernate.version} + org.jboss.logging jboss-logging @@ -562,14 +598,14 @@ com.fasterxml classmate - + org.hibernate.javax.persistence hibernate-jpa-2.1-api 1.0.0.Final - + mysql