repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
g0dkar/ajuda-ai
ajuda.ai/model/src/main/java/ajuda/ai/model/institution/InstitutionPost.java
// Path: ajuda.ai/model/src/main/java/ajuda/ai/model/extra/Page.java // @Entity // @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) // public class Page implements Serializable { // private static final long serialVersionUID = 1L; // // @Id @GeneratedValue(strategy = GenerationType.AUTO) // private Long id; // // /** "Endereço" desta entidade. Se {@code exemplo} for o slug podemos ter algo como {@code https://ajuda.ai/exemplo} */ // @NotBlank // @Size(min = 2, max = 128) // @Column(nullable = false, length = 128) // @Pattern(regexp = "[a-z][a-z0-9\\-]*[a-z0-9](/[a-z][a-z0-9\\-]*[a-z0-9])?") // private String slug; // // @Embedded // private CreationInfo creation; // // @URL // @Size(max = 1024) // @Column(length = 1024) // private String headerImage; // // @NotBlank // @Size(max = 128) // @Column(nullable = false, length = 128) // private String title; // // @Size(max = 128) // @Column(length = 128) // private String subtitle; // // @NotBlank // @Size(max = 65525) // @Column(nullable = false, columnDefinition = "MEDIUMTEXT") // private String content; // // @Column(nullable = false) // private boolean published; // // @PreUpdate // @PrePersist // public void beforeSave() { // if (title != null) { // title = title.replaceAll("\\s+", " ").trim(); // } // // if (content != null) { // content = content.trim(); // } // // if (slug == null) { // slug = StringUtils.slug(title); // } // } // // public CreationInfo getCreation() { // return creation; // } // // public void setCreation(final CreationInfo creation) { // this.creation = creation; // } // // public String getTitle() { // return title; // } // // public void setTitle(final String title) { // this.title = title; // } // // public String getContent() { // return content; // } // // public String getContentMarkdown() { // return StringUtils.markdown(content); // } // // public void setContent(final String content) { // this.content = content; // } // // public boolean isPublished() { // return published; // } // // public void setPublished(final boolean published) { // this.published = published; // } // // public String getHeaderImage() { // return headerImage; // } // // public void setHeaderImage(final String headerImage) { // this.headerImage = headerImage; // } // // public String getSubtitle() { // return subtitle; // } // // public void setSubtitle(final String subtitle) { // this.subtitle = subtitle; // } // // public Long getId() { // return id; // } // // public void setId(final Long id) { // this.id = id; // } // // public String getSlug() { // return slug; // } // // public void setSlug(final String slug) { // this.slug = slug; // } // }
import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Index; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.validation.constraints.NotNull; import ajuda.ai.model.extra.Page;
package ajuda.ai.model.institution; /** * Um post feito por uma {@link Institution Instituição} na página da mesma. * * @author Rafael Lins - g0dkar * */ @Entity @Table(indexes = { @Index(name = "unique_post_per_institution", unique = true, columnList = "slug, institution") })
// Path: ajuda.ai/model/src/main/java/ajuda/ai/model/extra/Page.java // @Entity // @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) // public class Page implements Serializable { // private static final long serialVersionUID = 1L; // // @Id @GeneratedValue(strategy = GenerationType.AUTO) // private Long id; // // /** "Endereço" desta entidade. Se {@code exemplo} for o slug podemos ter algo como {@code https://ajuda.ai/exemplo} */ // @NotBlank // @Size(min = 2, max = 128) // @Column(nullable = false, length = 128) // @Pattern(regexp = "[a-z][a-z0-9\\-]*[a-z0-9](/[a-z][a-z0-9\\-]*[a-z0-9])?") // private String slug; // // @Embedded // private CreationInfo creation; // // @URL // @Size(max = 1024) // @Column(length = 1024) // private String headerImage; // // @NotBlank // @Size(max = 128) // @Column(nullable = false, length = 128) // private String title; // // @Size(max = 128) // @Column(length = 128) // private String subtitle; // // @NotBlank // @Size(max = 65525) // @Column(nullable = false, columnDefinition = "MEDIUMTEXT") // private String content; // // @Column(nullable = false) // private boolean published; // // @PreUpdate // @PrePersist // public void beforeSave() { // if (title != null) { // title = title.replaceAll("\\s+", " ").trim(); // } // // if (content != null) { // content = content.trim(); // } // // if (slug == null) { // slug = StringUtils.slug(title); // } // } // // public CreationInfo getCreation() { // return creation; // } // // public void setCreation(final CreationInfo creation) { // this.creation = creation; // } // // public String getTitle() { // return title; // } // // public void setTitle(final String title) { // this.title = title; // } // // public String getContent() { // return content; // } // // public String getContentMarkdown() { // return StringUtils.markdown(content); // } // // public void setContent(final String content) { // this.content = content; // } // // public boolean isPublished() { // return published; // } // // public void setPublished(final boolean published) { // this.published = published; // } // // public String getHeaderImage() { // return headerImage; // } // // public void setHeaderImage(final String headerImage) { // this.headerImage = headerImage; // } // // public String getSubtitle() { // return subtitle; // } // // public void setSubtitle(final String subtitle) { // this.subtitle = subtitle; // } // // public Long getId() { // return id; // } // // public void setId(final Long id) { // this.id = id; // } // // public String getSlug() { // return slug; // } // // public void setSlug(final String slug) { // this.slug = slug; // } // } // Path: ajuda.ai/model/src/main/java/ajuda/ai/model/institution/InstitutionPost.java import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Index; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.validation.constraints.NotNull; import ajuda.ai.model.extra.Page; package ajuda.ai.model.institution; /** * Um post feito por uma {@link Institution Instituição} na página da mesma. * * @author Rafael Lins - g0dkar * */ @Entity @Table(indexes = { @Index(name = "unique_post_per_institution", unique = true, columnList = "slug, institution") })
public class InstitutionPost extends Page implements Serializable {
g0dkar/ajuda-ai
ajuda.ai/payment-api/src/main/java/ajuda/ai/payment/PaymentService.java
// Path: ajuda.ai/payment-api/src/main/java/ajuda/ai/payment/exception/UnsupportedPaymentServiceException.java // public class UnsupportedPaymentServiceException extends RuntimeException { // private static final long serialVersionUID = 5985711746057579224L; // // public UnsupportedPaymentServiceException() { // super(); // } // // public UnsupportedPaymentServiceException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { // super(arg0, arg1, arg2, arg3); // } // // public UnsupportedPaymentServiceException(String arg0, Throwable arg1) { // super(arg0, arg1); // } // // public UnsupportedPaymentServiceException(String arg0) { // super(arg0); // } // // public UnsupportedPaymentServiceException(Throwable arg0) { // super(arg0); // } // }
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Instance; import javax.inject.Inject; import ajuda.ai.payment.exception.UnsupportedPaymentServiceException;
package ajuda.ai.payment; /** * Mantém um registro dos serviços de pagamento e instancia as implementações. * * @author Rafael Lins * */ @ApplicationScoped public class PaymentService { @Inject @ajuda.ai.payment.annotation.PaymentService private Instance<PaymentGateway> processors; /** * @param service Serviço de pagamento * @return Um {@link PaymentGateway} do serviço especificado */ public PaymentGateway get(String service) { for (PaymentGateway paymentProcessor : processors) { ajuda.ai.payment.annotation.PaymentService annotation = paymentProcessor.getClass().getAnnotation(ajuda.ai.payment.annotation.PaymentService.class); if (annotation.value().equals(service)) { return paymentProcessor; } }
// Path: ajuda.ai/payment-api/src/main/java/ajuda/ai/payment/exception/UnsupportedPaymentServiceException.java // public class UnsupportedPaymentServiceException extends RuntimeException { // private static final long serialVersionUID = 5985711746057579224L; // // public UnsupportedPaymentServiceException() { // super(); // } // // public UnsupportedPaymentServiceException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { // super(arg0, arg1, arg2, arg3); // } // // public UnsupportedPaymentServiceException(String arg0, Throwable arg1) { // super(arg0, arg1); // } // // public UnsupportedPaymentServiceException(String arg0) { // super(arg0); // } // // public UnsupportedPaymentServiceException(Throwable arg0) { // super(arg0); // } // } // Path: ajuda.ai/payment-api/src/main/java/ajuda/ai/payment/PaymentService.java import javax.enterprise.context.ApplicationScoped; import javax.enterprise.inject.Instance; import javax.inject.Inject; import ajuda.ai.payment.exception.UnsupportedPaymentServiceException; package ajuda.ai.payment; /** * Mantém um registro dos serviços de pagamento e instancia as implementações. * * @author Rafael Lins * */ @ApplicationScoped public class PaymentService { @Inject @ajuda.ai.payment.annotation.PaymentService private Instance<PaymentGateway> processors; /** * @param service Serviço de pagamento * @return Um {@link PaymentGateway} do serviço especificado */ public PaymentGateway get(String service) { for (PaymentGateway paymentProcessor : processors) { ajuda.ai.payment.annotation.PaymentService annotation = paymentProcessor.getClass().getAnnotation(ajuda.ai.payment.annotation.PaymentService.class); if (annotation.value().equals(service)) { return paymentProcessor; } }
throw new UnsupportedPaymentServiceException(service);
g0dkar/ajuda-ai
ajuda.ai/backend/src/main/java/ajuda/ai/backend/v1/cors/CORSController.java
// Path: ajuda.ai/persistence-sql/src/main/java/ajuda/ai/persistence/model/ConfigurationPersistence.java // @RequestScoped // public class ConfigurationPersistence implements Persistence<Configuration> { // private final PersistenceService ps; // // /** @deprecated CDI */ @Deprecated // ConfigurationPersistence() { this(null); } // // @Inject // public ConfigurationPersistence(PersistenceService ps) { // this.ps = ps; // } // // @Override // public Configuration get(Long id) { // return ps.find(Configuration.class, id); // } // // public Configuration getConfiguration(String name) { // return (Configuration) ps.createQuery("FROM Configuration WHERE name = :name").setParameter("name", name).getSingleResult(); // } // // public String get(String configuration) { // return get(configuration, (String) null); // } // // public String get(String configuration, String defaultValue) { // String value = (String) ps.createQuery("SELECT value FROM Configuration WHERE name = :name").setParameter("name", configuration).getSingleResult(); // return value != null ? value : defaultValue; // } // // public void set(String configuration, String value) { // Configuration conf = getConfiguration(configuration); // if (conf == null) { // conf = new Configuration(); // conf.setName(configuration); // } // conf.setValue(value); // // if (conf.getId() == null) { // persist(conf); // } // else { // merge(conf); // } // } // // public int get(String configuration, int defaultValue) { // String value = get(configuration); // return StringUtils.isNumber(value) ? Integer.parseInt(value, 10) : defaultValue; // } // // public void set(String configuration, int value) { // set(configuration, Integer.toString(value, 10)); // } // // public long get(String configuration, long defaultValue) { // String value = get(configuration); // return StringUtils.isNumber(value) ? Long.parseLong(value, 10) : defaultValue; // } // // public void set(String configuration, long value) { // set(configuration, Long.toString(value, 10)); // } // // public double get(String configuration, double defaultValue) { // String value = get(configuration); // // try { // return Double.parseDouble(value); // } catch (Exception e) { // return defaultValue; // } // } // // public void set(String configuration, double value) { // set(configuration, Double.toString(value)); // } // // public Instant get(String configuration, Instant defaultValue) { // String value = get(configuration); // // try { // return Instant.parse(value); // } catch (Exception e) { // return defaultValue; // } // } // // public void set(String configuration, Instant value) { // set(configuration, value.toString()); // } // // public Date get(String configuration, Date defaultValue) { // String value = get(configuration); // // try { // return new Date(Instant.parse(value).toEpochMilli()); // } catch (Exception e) { // return defaultValue; // } // } // // public void set(String configuration, Date value) { // set(configuration, Instant.ofEpochMilli(value.getTime()).toString()); // } // // // @Override // public void persist(Configuration object) { // ps.persist(object); // } // // @Override // public Configuration merge(Configuration object) { // return ps.merge(object); // } // // @Override // public Configuration remove(Configuration object) { // ps.remove(object); // return object; // } // // @Override // public Query query(String query) { // return ps.createQuery(query); // } // }
import java.time.Instant; import java.time.temporal.ChronoUnit; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ajuda.ai.persistence.model.ConfigurationPersistence; import br.com.caelum.vraptor.Controller; import br.com.caelum.vraptor.Options; import br.com.caelum.vraptor.Result;
package ajuda.ai.backend.v1.cors; /** * Implementa de forma bem simples e direta o protocolo CORS (Cross-Origin Resource Sharing) * * @author Rafael Lins * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS * */ @Controller public class CORSController { private final Result result; private final HttpServletRequest request; private final HttpServletResponse response;
// Path: ajuda.ai/persistence-sql/src/main/java/ajuda/ai/persistence/model/ConfigurationPersistence.java // @RequestScoped // public class ConfigurationPersistence implements Persistence<Configuration> { // private final PersistenceService ps; // // /** @deprecated CDI */ @Deprecated // ConfigurationPersistence() { this(null); } // // @Inject // public ConfigurationPersistence(PersistenceService ps) { // this.ps = ps; // } // // @Override // public Configuration get(Long id) { // return ps.find(Configuration.class, id); // } // // public Configuration getConfiguration(String name) { // return (Configuration) ps.createQuery("FROM Configuration WHERE name = :name").setParameter("name", name).getSingleResult(); // } // // public String get(String configuration) { // return get(configuration, (String) null); // } // // public String get(String configuration, String defaultValue) { // String value = (String) ps.createQuery("SELECT value FROM Configuration WHERE name = :name").setParameter("name", configuration).getSingleResult(); // return value != null ? value : defaultValue; // } // // public void set(String configuration, String value) { // Configuration conf = getConfiguration(configuration); // if (conf == null) { // conf = new Configuration(); // conf.setName(configuration); // } // conf.setValue(value); // // if (conf.getId() == null) { // persist(conf); // } // else { // merge(conf); // } // } // // public int get(String configuration, int defaultValue) { // String value = get(configuration); // return StringUtils.isNumber(value) ? Integer.parseInt(value, 10) : defaultValue; // } // // public void set(String configuration, int value) { // set(configuration, Integer.toString(value, 10)); // } // // public long get(String configuration, long defaultValue) { // String value = get(configuration); // return StringUtils.isNumber(value) ? Long.parseLong(value, 10) : defaultValue; // } // // public void set(String configuration, long value) { // set(configuration, Long.toString(value, 10)); // } // // public double get(String configuration, double defaultValue) { // String value = get(configuration); // // try { // return Double.parseDouble(value); // } catch (Exception e) { // return defaultValue; // } // } // // public void set(String configuration, double value) { // set(configuration, Double.toString(value)); // } // // public Instant get(String configuration, Instant defaultValue) { // String value = get(configuration); // // try { // return Instant.parse(value); // } catch (Exception e) { // return defaultValue; // } // } // // public void set(String configuration, Instant value) { // set(configuration, value.toString()); // } // // public Date get(String configuration, Date defaultValue) { // String value = get(configuration); // // try { // return new Date(Instant.parse(value).toEpochMilli()); // } catch (Exception e) { // return defaultValue; // } // } // // public void set(String configuration, Date value) { // set(configuration, Instant.ofEpochMilli(value.getTime()).toString()); // } // // // @Override // public void persist(Configuration object) { // ps.persist(object); // } // // @Override // public Configuration merge(Configuration object) { // return ps.merge(object); // } // // @Override // public Configuration remove(Configuration object) { // ps.remove(object); // return object; // } // // @Override // public Query query(String query) { // return ps.createQuery(query); // } // } // Path: ajuda.ai/backend/src/main/java/ajuda/ai/backend/v1/cors/CORSController.java import java.time.Instant; import java.time.temporal.ChronoUnit; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ajuda.ai.persistence.model.ConfigurationPersistence; import br.com.caelum.vraptor.Controller; import br.com.caelum.vraptor.Options; import br.com.caelum.vraptor.Result; package ajuda.ai.backend.v1.cors; /** * Implementa de forma bem simples e direta o protocolo CORS (Cross-Origin Resource Sharing) * * @author Rafael Lins * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS * */ @Controller public class CORSController { private final Result result; private final HttpServletRequest request; private final HttpServletResponse response;
private final ConfigurationPersistence cp;
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/ProjectControllerTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class ProjectControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.project+json"); @Autowired
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/ProjectControllerTest.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class ProjectControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.project+json"); @Autowired
private volatile ProjectRepository projectRepository;
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/ProjectControllerTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class ProjectControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.project+json"); @Autowired private volatile ProjectRepository projectRepository; @Test public void create() throws Exception { this.mockMvc.perform(post("/projects").contentType(MEDIA_TYPE) .content(toJson("key:TEST_KEY", "name:Test Name"))) .andExpect(status().isCreated()) .andExpect(header().string("Location", "http://localhost/projects/TEST_KEY")); assertEquals(1, countRowsInTable("project")); } @Test public void createDuplicate() throws Exception {
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/ProjectControllerTest.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class ProjectControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.project+json"); @Autowired private volatile ProjectRepository projectRepository; @Test public void create() throws Exception { this.mockMvc.perform(post("/projects").contentType(MEDIA_TYPE) .content(toJson("key:TEST_KEY", "name:Test Name"))) .andExpect(status().isCreated()) .andExpect(header().string("Location", "http://localhost/projects/TEST_KEY")); assertEquals(1, countRowsInTable("project")); } @Test public void createDuplicate() throws Exception {
this.projectRepository.saveAndFlush(new Project("TEST_KEY", "Test Name"));
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/BuildControllerTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // }
import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class BuildControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.build+json"); @Autowired
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/BuildControllerTest.java import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class BuildControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.build+json"); @Autowired
private volatile ProjectRepository projectRepository;
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/BuildControllerTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // }
import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class BuildControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.build+json"); @Autowired private volatile ProjectRepository projectRepository; @Autowired
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/BuildControllerTest.java import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.repository.ProjectRepository; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public class BuildControllerTest extends AbstractControllerTest { private static final MediaType MEDIA_TYPE = MediaType.valueOf("application/vnd.nebhale.buildmonitor.build+json"); @Autowired private volatile ProjectRepository projectRepository; @Autowired
private volatile BuildRepository buildRepository;
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/TravisPayloadParserTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // }
import com.nebhale.buildmonitor.domain.Build; import org.junit.Test; import java.io.IOException;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public final class TravisPayloadParserTest extends AbstractPayloadParserTest { public TravisPayloadParserTest() { super(new TravisPayloadParser()); } @Test public void getStatePending() throws IOException {
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // Path: src/test/java/com/nebhale/buildmonitor/web/TravisPayloadParserTest.java import com.nebhale.buildmonitor.domain.Build; import org.junit.Test; import java.io.IOException; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public final class TravisPayloadParserTest extends AbstractPayloadParserTest { public TravisPayloadParserTest() { super(new TravisPayloadParser()); } @Test public void getStatePending() throws IOException {
assertState("travis-pending-webhook.json", Build.State.IN_PROGRESS);
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/TravisPayloadParser.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // }
import com.nebhale.buildmonitor.domain.Build; import org.springframework.stereotype.Component; import java.util.Map; import java.util.regex.Pattern;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; @Component final class TravisPayloadParser implements WebHookController.PayloadParser { private static final Pattern PULL_REQUEST = Pattern.compile(".*/pull/[\\d]+"); private static final String STATUS_BROKEN = "Broken"; private static final String STATUS_ERRORED = "Errored"; private static final String STATUS_FAILED = "Failed"; private static final String STATUS_FIXED = "Fixed"; private static final String STATUS_PASSED = "Passed"; private static final String STATUS_PENDING = "Pending"; private static final String STATUS_STILL_FAILING = "Still Failing"; @Override
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // Path: src/main/java/com/nebhale/buildmonitor/web/TravisPayloadParser.java import com.nebhale.buildmonitor.domain.Build; import org.springframework.stereotype.Component; import java.util.Map; import java.util.regex.Pattern; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; @Component final class TravisPayloadParser implements WebHookController.PayloadParser { private static final Pattern PULL_REQUEST = Pattern.compile(".*/pull/[\\d]+"); private static final String STATUS_BROKEN = "Broken"; private static final String STATUS_ERRORED = "Errored"; private static final String STATUS_FAILED = "Failed"; private static final String STATUS_FIXED = "Fixed"; private static final String STATUS_PASSED = "Passed"; private static final String STATUS_PENDING = "Pending"; private static final String STATUS_STILL_FAILING = "Still Failing"; @Override
public Build.State getState(Map<String, ?> payload) {
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifierTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.junit.Test; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingProjectsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class);
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifierTest.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.junit.Test; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingProjectsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class);
private final ProjectRepository repository = mock(ProjectRepository.class);
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifierTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.junit.Test; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingProjectsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class); private final ProjectRepository repository = mock(ProjectRepository.class);
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifierTest.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.junit.Test; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingProjectsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class); private final ProjectRepository repository = mock(ProjectRepository.class);
private final ProjectResourceAssembler resourceAssembler = mock(ProjectResourceAssembler.class);
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifierTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.junit.Test; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingProjectsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class); private final ProjectRepository repository = mock(ProjectRepository.class); private final ProjectResourceAssembler resourceAssembler = mock(ProjectResourceAssembler.class); private final MessagingProjectsChangedNotifier notifier = new MessagingProjectsChangedNotifier(this .messageTemplate, this.repository, this.resourceAssembler); @Test @SuppressWarnings("unchecked") public void projectsChanged() {
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifierTest.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.junit.Test; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingProjectsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class); private final ProjectRepository repository = mock(ProjectRepository.class); private final ProjectResourceAssembler resourceAssembler = mock(ProjectResourceAssembler.class); private final MessagingProjectsChangedNotifier notifier = new MessagingProjectsChangedNotifier(this .messageTemplate, this.repository, this.resourceAssembler); @Test @SuppressWarnings("unchecked") public void projectsChanged() {
Project project1 = new Project("TEST-KEY-1", "Test Name 1");
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/JenkinsPayloadParser.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // }
import com.nebhale.buildmonitor.domain.Build; import org.springframework.stereotype.Component; import java.util.Map;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; @Component final class JenkinsPayloadParser implements WebHookController.PayloadParser { @Override
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // Path: src/main/java/com/nebhale/buildmonitor/web/JenkinsPayloadParser.java import com.nebhale.buildmonitor.domain.Build; import org.springframework.stereotype.Component; import java.util.Map; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; @Component final class JenkinsPayloadParser implements WebHookController.PayloadParser { @Override
public Build.State getState(Map<String, ?> payload) {
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/ProjectController.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json";
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/ProjectController.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json";
private final ProjectsChangedNotifier projectsChangedNotifier;
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/ProjectController.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json"; private final ProjectsChangedNotifier projectsChangedNotifier;
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/ProjectController.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json"; private final ProjectsChangedNotifier projectsChangedNotifier;
private final ProjectRepository repository;
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/ProjectController.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json"; private final ProjectsChangedNotifier projectsChangedNotifier; private final ProjectRepository repository;
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/ProjectController.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json"; private final ProjectsChangedNotifier projectsChangedNotifier; private final ProjectRepository repository;
private final ProjectResourceAssembler resourceAssembler;
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/ProjectController.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json"; private final ProjectsChangedNotifier projectsChangedNotifier; private final ProjectRepository repository; private final ProjectResourceAssembler resourceAssembler; @Autowired ProjectController(ProjectsChangedNotifier projectsChangedNotifier, ProjectRepository repository, ProjectResourceAssembler resourceAssembler) { this.projectsChangedNotifier = projectsChangedNotifier; this.repository = repository; this.resourceAssembler = resourceAssembler; } @Transactional @RequestMapping(method = RequestMethod.POST, value = "", produces = MEDIA_TYPE)
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/notify/ProjectsChangedNotifier.java // public interface ProjectsChangedNotifier { // // /** // * Notifies listeners that the collection of projects have changed // */ // void projectsChanged(); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/ProjectController.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.notify.ProjectsChangedNotifier; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; /** * Controller for accessing {@link Project}s */ @Controller @RequestMapping("/projects") public final class ProjectController { private static final String MEDIA_TYPE = "application/vnd.nebhale.buildmonitor.project+json"; private final ProjectsChangedNotifier projectsChangedNotifier; private final ProjectRepository repository; private final ProjectResourceAssembler resourceAssembler; @Autowired ProjectController(ProjectsChangedNotifier projectsChangedNotifier, ProjectRepository repository, ProjectResourceAssembler resourceAssembler) { this.projectsChangedNotifier = projectsChangedNotifier; this.repository = repository; this.resourceAssembler = resourceAssembler; } @Transactional @RequestMapping(method = RequestMethod.POST, value = "", produces = MEDIA_TYPE)
ResponseEntity<?> create(@RequestBody Project project) {
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/resource/StandardBuildResourceAssemblerTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // }
import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import org.junit.Test; import org.springframework.hateoas.Resource; import static org.junit.Assert.assertEquals;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.resource; public final class StandardBuildResourceAssemblerTest extends AbstractResourceAssemblerTest { private final Project project = new Project("test-key", "test-name");
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // Path: src/test/java/com/nebhale/buildmonitor/web/resource/StandardBuildResourceAssemblerTest.java import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import org.junit.Test; import org.springframework.hateoas.Resource; import static org.junit.Assert.assertEquals; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.resource; public final class StandardBuildResourceAssemblerTest extends AbstractResourceAssemblerTest { private final Project project = new Project("test-key", "test-name");
private final Build build = new Build(this.project, "test-uri", Build.State.PASS);
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/JenkinsPayloadParserTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // }
import com.nebhale.buildmonitor.domain.Build; import org.junit.Test; import java.io.IOException;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public final class JenkinsPayloadParserTest extends AbstractPayloadParserTest { public JenkinsPayloadParserTest() { super(new JenkinsPayloadParser()); } @Test public void getStateStart() throws Exception {
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // Path: src/test/java/com/nebhale/buildmonitor/web/JenkinsPayloadParserTest.java import com.nebhale.buildmonitor.domain.Build; import org.junit.Test; import java.io.IOException; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public final class JenkinsPayloadParserTest extends AbstractPayloadParserTest { public JenkinsPayloadParserTest() { super(new JenkinsPayloadParser()); } @Test public void getStateStart() throws Exception {
assertState("jenkins-in-progress-webhook.json", Build.State.IN_PROGRESS);
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/AbstractPayloadParserTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // }
import com.fasterxml.jackson.databind.ObjectMapper; import com.nebhale.buildmonitor.domain.Build; import org.junit.Assert; import java.io.File; import java.io.IOException; import java.util.Map;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public abstract class AbstractPayloadParserTest { private final ObjectMapper objectMapper = new ObjectMapper(); private final WebHookController.PayloadParser payloadParser; AbstractPayloadParserTest(WebHookController.PayloadParser payloadParser) { this.payloadParser = payloadParser; } final void assertShouldProcess(String filename, Boolean shouldProcess) throws IOException { Assert.assertEquals(shouldProcess, this.payloadParser.shouldProcess(getPayload(filename))); }
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // Path: src/test/java/com/nebhale/buildmonitor/web/AbstractPayloadParserTest.java import com.fasterxml.jackson.databind.ObjectMapper; import com.nebhale.buildmonitor.domain.Build; import org.junit.Assert; import java.io.File; import java.io.IOException; import java.util.Map; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web; public abstract class AbstractPayloadParserTest { private final ObjectMapper objectMapper = new ObjectMapper(); private final WebHookController.PayloadParser payloadParser; AbstractPayloadParserTest(WebHookController.PayloadParser payloadParser) { this.payloadParser = payloadParser; } final void assertShouldProcess(String filename, Boolean shouldProcess) throws IOException { Assert.assertEquals(shouldProcess, this.payloadParser.shouldProcess(getPayload(filename))); }
final void assertState(String filename, Build.State state) throws IOException {
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/notify/MessagingBuildsChangedNotifier.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/BuildResourceAssembler.java // public interface BuildResourceAssembler extends ResourceAssembler<Build, Resource<Build>> { // // }
import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.web.resource.BuildResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingBuildsChangedNotifier implements BuildsChangedNotifier { private static final Pageable PAGE = new PageRequest(0, 10); private final MessageSendingOperations<String> messageTemplate;
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/BuildResourceAssembler.java // public interface BuildResourceAssembler extends ResourceAssembler<Build, Resource<Build>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/notify/MessagingBuildsChangedNotifier.java import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.web.resource.BuildResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingBuildsChangedNotifier implements BuildsChangedNotifier { private static final Pageable PAGE = new PageRequest(0, 10); private final MessageSendingOperations<String> messageTemplate;
private final BuildRepository repository;
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/notify/MessagingBuildsChangedNotifier.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/BuildResourceAssembler.java // public interface BuildResourceAssembler extends ResourceAssembler<Build, Resource<Build>> { // // }
import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.web.resource.BuildResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingBuildsChangedNotifier implements BuildsChangedNotifier { private static final Pageable PAGE = new PageRequest(0, 10); private final MessageSendingOperations<String> messageTemplate; private final BuildRepository repository;
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/BuildResourceAssembler.java // public interface BuildResourceAssembler extends ResourceAssembler<Build, Resource<Build>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/notify/MessagingBuildsChangedNotifier.java import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.web.resource.BuildResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingBuildsChangedNotifier implements BuildsChangedNotifier { private static final Pageable PAGE = new PageRequest(0, 10); private final MessageSendingOperations<String> messageTemplate; private final BuildRepository repository;
private final BuildResourceAssembler resourceAssembler;
nebhale/build-monitor
src/test/java/com/nebhale/buildmonitor/web/notify/MessagingBuildsChangedNotifierTest.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/BuildResourceAssembler.java // public interface BuildResourceAssembler extends ResourceAssembler<Build, Resource<Build>> { // // }
import static org.mockito.Mockito.when; import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.web.resource.BuildResourceAssembler; import org.junit.Test; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingBuildsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class);
// Path: src/main/java/com/nebhale/buildmonitor/domain/Build.java // @Entity // public final class Build { // // @Id // @GeneratedValue(strategy = GenerationType.IDENTITY) // private volatile Integer id; // // private volatile Date created; // // @JoinColumn(name = "project") // TODO: Remove once H2 supports column rename in PostgreSQL compatibility mode // @ManyToOne // @NotNull // private volatile Project project; // // @Size(min = 1, max = 256) // private volatile String uri; // // @NotNull // private volatile State state; // // Build() { // } // // /** // * Creates a new instance // * // * @param project the project that the build belongs to // * @param uri the uri of the build // * @param state the state of the build // */ // public Build(Project project, String uri, State state) { // this.created = new Date(); // this.project = project; // this.uri = uri; // this.state = state; // } // // /** // * Returns the id of the build // * // * @return the id of the build // */ // @JsonIgnore // public Integer getId() { // return this.id; // } // // /** // * Returns the date that the build was created // * // * @return the date that the build was created // */ // public Date getCreated() { // return this.created; // } // // /** // * Returns the project that the build belongs to // * // * @return the project that the build belongs to // */ // @JsonIgnore // public Project getProject() { // return this.project; // } // // /** // * Returns the uri of the build // * // * @return the uri of the build // */ // public String getUri() { // return this.uri; // } // // /** // * Returns the state of the build // * // * @return the state of the build // */ // public State getState() { // return this.state; // } // // /** // * Set the state of the build // * // * @param state the state of the build // */ // public void setState(State state) { // this.state = state; // } // // /** // * The state of a {@link Build} // */ // public enum State { // // /** // * The build has failed // */ // FAIL, // // /** // * The build is currently in progress // */ // IN_PROGRESS, // // /** // * The build has passed // */ // PASS, // // /** // * The build is in an unknown state // */ // UNKNOWN // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/BuildRepository.java // public interface BuildRepository extends JpaRepository<Build, Integer> { // // /** // * Returns all builds belonging to a project sorted by their creation date, descending // * // * @param project the project that the builds belong to // * @param pageable the paging configuration // * // * @return all builds belonging to a project sorted by their creation date, descending // */ // Page<Build> findAllByProjectOrderByCreatedDesc(Project project, Pageable pageable); // // /** // * Returns a build uniquely identified by it's URI, otherwise {@literal null} // * // * @param uri the URI that uniquely identifies a build // * // * @return a build uniquely identified by it's URI, otherwise {@literal null} // */ // Build findByUri(String uri); // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/BuildResourceAssembler.java // public interface BuildResourceAssembler extends ResourceAssembler<Build, Resource<Build>> { // // } // Path: src/test/java/com/nebhale/buildmonitor/web/notify/MessagingBuildsChangedNotifierTest.java import static org.mockito.Mockito.when; import com.nebhale.buildmonitor.domain.Build; import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.BuildRepository; import com.nebhale.buildmonitor.web.resource.BuildResourceAssembler; import org.junit.Test; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; public final class MessagingBuildsChangedNotifierTest { @SuppressWarnings("unchecked") private final MessageSendingOperations<String> messageTemplate = mock(MessageSendingOperations.class);
private final BuildRepository repository = mock(BuildRepository.class);
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifier.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingProjectsChangedNotifier implements ProjectsChangedNotifier { private final MessageSendingOperations<String> messageTemplate;
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifier.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingProjectsChangedNotifier implements ProjectsChangedNotifier { private final MessageSendingOperations<String> messageTemplate;
private final ProjectRepository repository;
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifier.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingProjectsChangedNotifier implements ProjectsChangedNotifier { private final MessageSendingOperations<String> messageTemplate; private final ProjectRepository repository;
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifier.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingProjectsChangedNotifier implements ProjectsChangedNotifier { private final MessageSendingOperations<String> messageTemplate; private final ProjectRepository repository;
private final ProjectResourceAssembler resourceAssembler;
nebhale/build-monitor
src/main/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifier.java
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // }
import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors;
/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingProjectsChangedNotifier implements ProjectsChangedNotifier { private final MessageSendingOperations<String> messageTemplate; private final ProjectRepository repository; private final ProjectResourceAssembler resourceAssembler; @Autowired MessagingProjectsChangedNotifier(MessageSendingOperations<String> messageTemplate, ProjectRepository repository, ProjectResourceAssembler resourceAssembler) { this.messageTemplate = messageTemplate; this.repository = repository; this.resourceAssembler = resourceAssembler; } @Override public void projectsChanged() {
// Path: src/main/java/com/nebhale/buildmonitor/domain/Project.java // @Entity // public final class Project { // // @Id // @Size(min = 1, max = 8) // private volatile String key; // // @Size(min = 1, max = 64) // private volatile String name; // // Project() { // } // // /** // * Creates a new instance // * // * @param key the key of the project // * @param name the name of the project // */ // public Project(String key, String name) { // this.key = key.toUpperCase(); // this.name = name; // } // // /** // * Returns the key of the project // * // * @return the key of the project // */ // public String getKey() { // return this.key; // } // // /** // * Returns the name of the project // * // * @return the name of the project // */ // public String getName() { // return this.name; // } // // } // // Path: src/main/java/com/nebhale/buildmonitor/repository/ProjectRepository.java // public interface ProjectRepository extends JpaRepository<Project, String> { // // } // // Path: src/main/java/com/nebhale/buildmonitor/web/resource/ProjectResourceAssembler.java // public interface ProjectResourceAssembler extends ResourceAssembler<Project, Resource<Project>> { // // } // Path: src/main/java/com/nebhale/buildmonitor/web/notify/MessagingProjectsChangedNotifier.java import com.nebhale.buildmonitor.domain.Project; import com.nebhale.buildmonitor.repository.ProjectRepository; import com.nebhale.buildmonitor.web.resource.ProjectResourceAssembler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.hateoas.Resource; import org.springframework.messaging.core.MessageSendingOperations; import org.springframework.stereotype.Component; import java.util.List; import java.util.stream.Collectors; /* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.nebhale.buildmonitor.web.notify; @Component final class MessagingProjectsChangedNotifier implements ProjectsChangedNotifier { private final MessageSendingOperations<String> messageTemplate; private final ProjectRepository repository; private final ProjectResourceAssembler resourceAssembler; @Autowired MessagingProjectsChangedNotifier(MessageSendingOperations<String> messageTemplate, ProjectRepository repository, ProjectResourceAssembler resourceAssembler) { this.messageTemplate = messageTemplate; this.repository = repository; this.resourceAssembler = resourceAssembler; } @Override public void projectsChanged() {
List<Resource<Project>> resources = this.repository.findAll(new Sort("key")).stream()
k3po/k3po
lang/src/main/java/org/kaazing/k3po/lang/internal/ast/AstReadAdviseNode.java
// Path: lang/src/main/java/org/kaazing/k3po/lang/internal/ast/value/AstValue.java // public abstract class AstValue<T> extends AstRegion { // // public abstract <R, P> R accept(Visitor<R, P> visitor, P parameter); // // public interface Visitor<R, P> { // // R visit(AstExpressionValue<?> value, P parameter); // // R visit(AstLiteralTextValue value, P parameter); // // R visit(AstLiteralBytesValue value, P parameter); // // R visit(AstLiteralByteValue value, P parameter); // // R visit(AstLiteralShortValue value, P parameter); // // R visit(AstLiteralIntegerValue value, P parameter); // // R visit(AstLiteralLongValue value, P parameter); // // R visit(AstLiteralURIValue value, P parameter); // } // // public abstract T getValue(); // }
import static org.kaazing.k3po.lang.internal.ast.util.AstUtil.equivalent; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; import org.kaazing.k3po.lang.internal.ast.value.AstValue; import org.kaazing.k3po.lang.types.StructuredTypeInfo;
/** * Copyright 2007-2015, Kaazing Corporation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.kaazing.k3po.lang.internal.ast; public class AstReadAdviseNode extends AstCommandNode { private StructuredTypeInfo type;
// Path: lang/src/main/java/org/kaazing/k3po/lang/internal/ast/value/AstValue.java // public abstract class AstValue<T> extends AstRegion { // // public abstract <R, P> R accept(Visitor<R, P> visitor, P parameter); // // public interface Visitor<R, P> { // // R visit(AstExpressionValue<?> value, P parameter); // // R visit(AstLiteralTextValue value, P parameter); // // R visit(AstLiteralBytesValue value, P parameter); // // R visit(AstLiteralByteValue value, P parameter); // // R visit(AstLiteralShortValue value, P parameter); // // R visit(AstLiteralIntegerValue value, P parameter); // // R visit(AstLiteralLongValue value, P parameter); // // R visit(AstLiteralURIValue value, P parameter); // } // // public abstract T getValue(); // } // Path: lang/src/main/java/org/kaazing/k3po/lang/internal/ast/AstReadAdviseNode.java import static org.kaazing.k3po.lang.internal.ast.util.AstUtil.equivalent; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; import org.kaazing.k3po.lang.internal.ast.value.AstValue; import org.kaazing.k3po.lang.types.StructuredTypeInfo; /** * Copyright 2007-2015, Kaazing Corporation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.kaazing.k3po.lang.internal.ast; public class AstReadAdviseNode extends AstCommandNode { private StructuredTypeInfo type;
private Collection<AstValue<?>> values;
k3po/k3po
control/src/main/java/org/kaazing/k3po/control/internal/Control.java
// Path: control/src/main/java/org/kaazing/k3po/control/internal/command/CloseCommand.java // public final class CloseCommand extends Command { // // @Override // public Kind getKind() { // return Kind.CLOSE; // } // // @Override // public int hashCode() { // return Objects.hash(getKind()); // } // // @Override // public boolean equals(Object o) { // return o == this || o instanceof CloseCommand && equalTo((CloseCommand) o); // } // // } // // Path: control/src/main/java/org/kaazing/k3po/control/internal/command/Command.java // public abstract class Command { // // /** // * Kind of Command. // * // */ // public enum Kind { // /** // * Prepare command. // */ // PREPARE, // /** // * Start command. // */ // START, // /** // * Abort command. // */ // ABORT, // /** // * Await command. // */ // AWAIT, // /** // * Notify command. // */ // NOTIFY, // /** // * Close command. // */ // CLOSE // } // // /** // * @return Kind // */ // public abstract Kind getKind(); // // @Override // public abstract int hashCode(); // // @Override // public boolean equals(Object o) { // return o == this || o instanceof Command && equalTo((Command) o); // } // // protected final boolean equalTo(Command that) { // return Objects.equals(this.getKind(), that.getKind()); // } // // }
import static java.lang.Integer.parseInt; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.net.URLConnection; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.kaazing.k3po.control.internal.command.AbortCommand; import org.kaazing.k3po.control.internal.command.AwaitCommand; import org.kaazing.k3po.control.internal.command.CloseCommand; import org.kaazing.k3po.control.internal.command.Command; import org.kaazing.k3po.control.internal.command.NotifyCommand; import org.kaazing.k3po.control.internal.command.PrepareCommand; import org.kaazing.k3po.control.internal.command.StartCommand; import org.kaazing.k3po.control.internal.event.CommandEvent; import org.kaazing.k3po.control.internal.event.ErrorEvent; import org.kaazing.k3po.control.internal.event.FinishedEvent; import org.kaazing.k3po.control.internal.event.NotifiedEvent; import org.kaazing.k3po.control.internal.event.PreparedEvent; import org.kaazing.k3po.control.internal.event.StartedEvent;
public void disconnect() throws Exception { if (connection != null) { try { if (connection instanceof Closeable) { ((Closeable) connection).close(); } else { try { connection.getInputStream().close(); } catch (IOException e) { // ignore } try { connection.getOutputStream().close(); } catch (IOException e) { // ignore } } } finally { connection = null; } } } /** * Writes a command to the wire. * @param command to write to the wire * @throws Exception if the command is not recognized */
// Path: control/src/main/java/org/kaazing/k3po/control/internal/command/CloseCommand.java // public final class CloseCommand extends Command { // // @Override // public Kind getKind() { // return Kind.CLOSE; // } // // @Override // public int hashCode() { // return Objects.hash(getKind()); // } // // @Override // public boolean equals(Object o) { // return o == this || o instanceof CloseCommand && equalTo((CloseCommand) o); // } // // } // // Path: control/src/main/java/org/kaazing/k3po/control/internal/command/Command.java // public abstract class Command { // // /** // * Kind of Command. // * // */ // public enum Kind { // /** // * Prepare command. // */ // PREPARE, // /** // * Start command. // */ // START, // /** // * Abort command. // */ // ABORT, // /** // * Await command. // */ // AWAIT, // /** // * Notify command. // */ // NOTIFY, // /** // * Close command. // */ // CLOSE // } // // /** // * @return Kind // */ // public abstract Kind getKind(); // // @Override // public abstract int hashCode(); // // @Override // public boolean equals(Object o) { // return o == this || o instanceof Command && equalTo((Command) o); // } // // protected final boolean equalTo(Command that) { // return Objects.equals(this.getKind(), that.getKind()); // } // // } // Path: control/src/main/java/org/kaazing/k3po/control/internal/Control.java import static java.lang.Integer.parseInt; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.net.URLConnection; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.kaazing.k3po.control.internal.command.AbortCommand; import org.kaazing.k3po.control.internal.command.AwaitCommand; import org.kaazing.k3po.control.internal.command.CloseCommand; import org.kaazing.k3po.control.internal.command.Command; import org.kaazing.k3po.control.internal.command.NotifyCommand; import org.kaazing.k3po.control.internal.command.PrepareCommand; import org.kaazing.k3po.control.internal.command.StartCommand; import org.kaazing.k3po.control.internal.event.CommandEvent; import org.kaazing.k3po.control.internal.event.ErrorEvent; import org.kaazing.k3po.control.internal.event.FinishedEvent; import org.kaazing.k3po.control.internal.event.NotifiedEvent; import org.kaazing.k3po.control.internal.event.PreparedEvent; import org.kaazing.k3po.control.internal.event.StartedEvent; public void disconnect() throws Exception { if (connection != null) { try { if (connection instanceof Closeable) { ((Closeable) connection).close(); } else { try { connection.getInputStream().close(); } catch (IOException e) { // ignore } try { connection.getOutputStream().close(); } catch (IOException e) { // ignore } } } finally { connection = null; } } } /** * Writes a command to the wire. * @param command to write to the wire * @throws Exception if the command is not recognized */
public void writeCommand(Command command) throws Exception {
k3po/k3po
control/src/main/java/org/kaazing/k3po/control/internal/Control.java
// Path: control/src/main/java/org/kaazing/k3po/control/internal/command/CloseCommand.java // public final class CloseCommand extends Command { // // @Override // public Kind getKind() { // return Kind.CLOSE; // } // // @Override // public int hashCode() { // return Objects.hash(getKind()); // } // // @Override // public boolean equals(Object o) { // return o == this || o instanceof CloseCommand && equalTo((CloseCommand) o); // } // // } // // Path: control/src/main/java/org/kaazing/k3po/control/internal/command/Command.java // public abstract class Command { // // /** // * Kind of Command. // * // */ // public enum Kind { // /** // * Prepare command. // */ // PREPARE, // /** // * Start command. // */ // START, // /** // * Abort command. // */ // ABORT, // /** // * Await command. // */ // AWAIT, // /** // * Notify command. // */ // NOTIFY, // /** // * Close command. // */ // CLOSE // } // // /** // * @return Kind // */ // public abstract Kind getKind(); // // @Override // public abstract int hashCode(); // // @Override // public boolean equals(Object o) { // return o == this || o instanceof Command && equalTo((Command) o); // } // // protected final boolean equalTo(Command that) { // return Objects.equals(this.getKind(), that.getKind()); // } // // }
import static java.lang.Integer.parseInt; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.net.URLConnection; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.kaazing.k3po.control.internal.command.AbortCommand; import org.kaazing.k3po.control.internal.command.AwaitCommand; import org.kaazing.k3po.control.internal.command.CloseCommand; import org.kaazing.k3po.control.internal.command.Command; import org.kaazing.k3po.control.internal.command.NotifyCommand; import org.kaazing.k3po.control.internal.command.PrepareCommand; import org.kaazing.k3po.control.internal.command.StartCommand; import org.kaazing.k3po.control.internal.event.CommandEvent; import org.kaazing.k3po.control.internal.event.ErrorEvent; import org.kaazing.k3po.control.internal.event.FinishedEvent; import org.kaazing.k3po.control.internal.event.NotifiedEvent; import org.kaazing.k3po.control.internal.event.PreparedEvent; import org.kaazing.k3po.control.internal.event.StartedEvent;
} } } /** * Writes a command to the wire. * @param command to write to the wire * @throws Exception if the command is not recognized */ public void writeCommand(Command command) throws Exception { checkConnected(); switch (command.getKind()) { case PREPARE: writeCommand((PrepareCommand) command); break; case START: writeCommand((StartCommand) command); break; case ABORT: writeCommand((AbortCommand) command); break; case AWAIT: writeCommand((AwaitCommand) command); break; case NOTIFY: writeCommand((NotifyCommand) command); break; case CLOSE:
// Path: control/src/main/java/org/kaazing/k3po/control/internal/command/CloseCommand.java // public final class CloseCommand extends Command { // // @Override // public Kind getKind() { // return Kind.CLOSE; // } // // @Override // public int hashCode() { // return Objects.hash(getKind()); // } // // @Override // public boolean equals(Object o) { // return o == this || o instanceof CloseCommand && equalTo((CloseCommand) o); // } // // } // // Path: control/src/main/java/org/kaazing/k3po/control/internal/command/Command.java // public abstract class Command { // // /** // * Kind of Command. // * // */ // public enum Kind { // /** // * Prepare command. // */ // PREPARE, // /** // * Start command. // */ // START, // /** // * Abort command. // */ // ABORT, // /** // * Await command. // */ // AWAIT, // /** // * Notify command. // */ // NOTIFY, // /** // * Close command. // */ // CLOSE // } // // /** // * @return Kind // */ // public abstract Kind getKind(); // // @Override // public abstract int hashCode(); // // @Override // public boolean equals(Object o) { // return o == this || o instanceof Command && equalTo((Command) o); // } // // protected final boolean equalTo(Command that) { // return Objects.equals(this.getKind(), that.getKind()); // } // // } // Path: control/src/main/java/org/kaazing/k3po/control/internal/Control.java import static java.lang.Integer.parseInt; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.net.URLConnection; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.kaazing.k3po.control.internal.command.AbortCommand; import org.kaazing.k3po.control.internal.command.AwaitCommand; import org.kaazing.k3po.control.internal.command.CloseCommand; import org.kaazing.k3po.control.internal.command.Command; import org.kaazing.k3po.control.internal.command.NotifyCommand; import org.kaazing.k3po.control.internal.command.PrepareCommand; import org.kaazing.k3po.control.internal.command.StartCommand; import org.kaazing.k3po.control.internal.event.CommandEvent; import org.kaazing.k3po.control.internal.event.ErrorEvent; import org.kaazing.k3po.control.internal.event.FinishedEvent; import org.kaazing.k3po.control.internal.event.NotifiedEvent; import org.kaazing.k3po.control.internal.event.PreparedEvent; import org.kaazing.k3po.control.internal.event.StartedEvent; } } } /** * Writes a command to the wire. * @param command to write to the wire * @throws Exception if the command is not recognized */ public void writeCommand(Command command) throws Exception { checkConnected(); switch (command.getKind()) { case PREPARE: writeCommand((PrepareCommand) command); break; case START: writeCommand((StartCommand) command); break; case ABORT: writeCommand((AbortCommand) command); break; case AWAIT: writeCommand((AwaitCommand) command); break; case NOTIFY: writeCommand((NotifyCommand) command); break; case CLOSE:
writeCommand((CloseCommand) command);
k3po/k3po
driver/src/test/java/org/kaazing/k3po/driver/internal/behavior/handler/command/WriteHandlerTest.java
// Path: driver/src/main/java/org/kaazing/k3po/driver/internal/behavior/handler/codec/MessageEncoder.java // public interface MessageEncoder { // // ChannelBuffer encode(ChannelBufferFactory bufferFactory); // // }
import static java.lang.Boolean.TRUE; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.SECONDS; import static org.jboss.netty.buffer.ChannelBuffers.copiedBuffer; import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer; import static org.jboss.netty.channel.ChannelState.OPEN; import static org.jboss.netty.channel.Channels.fireWriteComplete; import static org.jboss.netty.channel.Channels.pipeline; import static org.jboss.netty.util.CharsetUtil.UTF_8; import static org.junit.Assert.assertFalse; import static org.kaazing.k3po.driver.internal.behavior.handler.codec.Maskers.newMasker; import static org.kaazing.k3po.lang.internal.el.ExpressionFactoryUtils.synchronizedSupplier; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.function.Supplier; import javax.el.ExpressionFactory; import javax.el.ValueExpression; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.ChannelDownstreamHandler; import org.jboss.netty.channel.ChannelEvent; import org.jboss.netty.channel.ChannelException; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelUpstreamHandler; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.channel.WriteCompletionEvent; import org.jboss.netty.channel.local.DefaultLocalClientChannelFactory; import org.jmock.lib.concurrent.Synchroniser; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.kaazing.k3po.driver.internal.behavior.handler.ExecutionHandler; import org.kaazing.k3po.driver.internal.behavior.handler.codec.Masker; import org.kaazing.k3po.driver.internal.behavior.handler.codec.MessageEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.codec.WriteBytesEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.codec.WriteExpressionEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.codec.WriteTextEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.prepare.PreparationEvent; import org.kaazing.k3po.driver.internal.jmock.Expectations; import org.kaazing.k3po.driver.internal.jmock.Mockery; import org.kaazing.k3po.lang.internal.el.ExpressionContext;
private Mockery context; private ChannelUpstreamHandler upstream; private ChannelDownstreamHandler downstream; private ChannelPipeline pipeline; private ChannelFactory channelFactory; private WriteHandler handler; private ExecutionHandler execution; private ExpressionContext environment; private ValueExpression expression; private Masker masker; public WriteHandlerTest(byte[] maskingKey) { this.maskingKey = maskingKey; } @Before public void setUp() throws Exception { context = new Mockery() { { setThrowFirstErrorOnAssertIsSatisfied(true); } }; context.setThreadingPolicy(new Synchroniser()); upstream = context.mock(ChannelUpstreamHandler.class); downstream = context.mock(ChannelDownstreamHandler.class); execution = new ExecutionHandler();
// Path: driver/src/main/java/org/kaazing/k3po/driver/internal/behavior/handler/codec/MessageEncoder.java // public interface MessageEncoder { // // ChannelBuffer encode(ChannelBufferFactory bufferFactory); // // } // Path: driver/src/test/java/org/kaazing/k3po/driver/internal/behavior/handler/command/WriteHandlerTest.java import static java.lang.Boolean.TRUE; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.SECONDS; import static org.jboss.netty.buffer.ChannelBuffers.copiedBuffer; import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer; import static org.jboss.netty.channel.ChannelState.OPEN; import static org.jboss.netty.channel.Channels.fireWriteComplete; import static org.jboss.netty.channel.Channels.pipeline; import static org.jboss.netty.util.CharsetUtil.UTF_8; import static org.junit.Assert.assertFalse; import static org.kaazing.k3po.driver.internal.behavior.handler.codec.Maskers.newMasker; import static org.kaazing.k3po.lang.internal.el.ExpressionFactoryUtils.synchronizedSupplier; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.function.Supplier; import javax.el.ExpressionFactory; import javax.el.ValueExpression; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.ChannelDownstreamHandler; import org.jboss.netty.channel.ChannelEvent; import org.jboss.netty.channel.ChannelException; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelUpstreamHandler; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.channel.WriteCompletionEvent; import org.jboss.netty.channel.local.DefaultLocalClientChannelFactory; import org.jmock.lib.concurrent.Synchroniser; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.kaazing.k3po.driver.internal.behavior.handler.ExecutionHandler; import org.kaazing.k3po.driver.internal.behavior.handler.codec.Masker; import org.kaazing.k3po.driver.internal.behavior.handler.codec.MessageEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.codec.WriteBytesEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.codec.WriteExpressionEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.codec.WriteTextEncoder; import org.kaazing.k3po.driver.internal.behavior.handler.prepare.PreparationEvent; import org.kaazing.k3po.driver.internal.jmock.Expectations; import org.kaazing.k3po.driver.internal.jmock.Mockery; import org.kaazing.k3po.lang.internal.el.ExpressionContext; private Mockery context; private ChannelUpstreamHandler upstream; private ChannelDownstreamHandler downstream; private ChannelPipeline pipeline; private ChannelFactory channelFactory; private WriteHandler handler; private ExecutionHandler execution; private ExpressionContext environment; private ValueExpression expression; private Masker masker; public WriteHandlerTest(byte[] maskingKey) { this.maskingKey = maskingKey; } @Before public void setUp() throws Exception { context = new Mockery() { { setThrowFirstErrorOnAssertIsSatisfied(true); } }; context.setThreadingPolicy(new Synchroniser()); upstream = context.mock(ChannelUpstreamHandler.class); downstream = context.mock(ChannelDownstreamHandler.class); execution = new ExecutionHandler();
List<MessageEncoder> encoders = new ArrayList<>();
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/rest/OneToManyEntityRESTService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/OneToManyEntity.java // @Entity // @Table(name = "OneToManyEntity") // @SequenceGenerator(name="seqOneToManyEntity", initialValue=10, allocationSize=100) // public class OneToManyEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToManyEntity() { // super(); // } // // public OneToManyEntity(String exampleString, Double exampleDouble, Integer exampleInt, Boolean exampleBool, BaseEntity baseEntity) { // super(); // this.exampleString = exampleString; // this.exampleDouble = exampleDouble; // this.exampleInt = exampleInt; // this.exampleBool = exampleBool; // this.baseEntity = baseEntity; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToManyEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // @Column(name="exampleDouble") // private Double exampleDouble; // // @Column(name="exampleInt") // private Integer exampleInt; // // @Column(name="exampleBool", columnDefinition="boolean default false") // private Boolean exampleBool; // // @ManyToOne(fetch=FetchType.LAZY) // @JoinColumns({ // @JoinColumn(name="basedentityid", referencedColumnName="id") // }) // @JsonIgnore // private BaseEntity baseEntity; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // public Double getExampleDouble() { // return exampleDouble; // } // // public void setExampleDouble(Double exampleDouble) { // this.exampleDouble = exampleDouble; // } // // public Integer getExampleInt() { // return exampleInt; // } // // public void setExampleInt(Integer exampleInt) { // this.exampleInt = exampleInt; // } // // public Boolean getExampleBool() { // return exampleBool; // } // // public void setExampleBool(Boolean exampleBool) { // this.exampleBool = exampleBool; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // }
import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.OneToManyEntity;
package com.bitfiction.mvctemplate.rest; @Path("/oneToManyEntity") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface OneToManyEntityRESTService { @GET @Path("/view")
// Path: src/main/java/com/bitfiction/mvctemplate/model/OneToManyEntity.java // @Entity // @Table(name = "OneToManyEntity") // @SequenceGenerator(name="seqOneToManyEntity", initialValue=10, allocationSize=100) // public class OneToManyEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToManyEntity() { // super(); // } // // public OneToManyEntity(String exampleString, Double exampleDouble, Integer exampleInt, Boolean exampleBool, BaseEntity baseEntity) { // super(); // this.exampleString = exampleString; // this.exampleDouble = exampleDouble; // this.exampleInt = exampleInt; // this.exampleBool = exampleBool; // this.baseEntity = baseEntity; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToManyEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // @Column(name="exampleDouble") // private Double exampleDouble; // // @Column(name="exampleInt") // private Integer exampleInt; // // @Column(name="exampleBool", columnDefinition="boolean default false") // private Boolean exampleBool; // // @ManyToOne(fetch=FetchType.LAZY) // @JoinColumns({ // @JoinColumn(name="basedentityid", referencedColumnName="id") // }) // @JsonIgnore // private BaseEntity baseEntity; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // public Double getExampleDouble() { // return exampleDouble; // } // // public void setExampleDouble(Double exampleDouble) { // this.exampleDouble = exampleDouble; // } // // public Integer getExampleInt() { // return exampleInt; // } // // public void setExampleInt(Integer exampleInt) { // this.exampleInt = exampleInt; // } // // public Boolean getExampleBool() { // return exampleBool; // } // // public void setExampleBool(Boolean exampleBool) { // this.exampleBool = exampleBool; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // } // Path: src/main/java/com/bitfiction/mvctemplate/rest/OneToManyEntityRESTService.java import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.OneToManyEntity; package com.bitfiction.mvctemplate.rest; @Path("/oneToManyEntity") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface OneToManyEntityRESTService { @GET @Path("/view")
public List<OneToManyEntity> view() throws Exception;
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm")
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm")
public class OneToOneEntityServiceImpl implements OneToOneEntityService {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityServiceImpl implements OneToOneEntityService { @Inject private EntityManager em; @Inject private Logger log;
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityServiceImpl implements OneToOneEntityService { @Inject private EntityManager em; @Inject private Logger log;
public List<OneToOneEntity> view(BaseEntity baseEntity) {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityServiceImpl implements OneToOneEntityService { @Inject private EntityManager em; @Inject private Logger log;
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityServiceImpl implements OneToOneEntityService { @Inject private EntityManager em; @Inject private Logger log;
public List<OneToOneEntity> view(BaseEntity baseEntity) {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/rest/UserInfoRESTService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // }
import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.UserInfo;
package com.bitfiction.mvctemplate.rest; @Path("/userInfo") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface UserInfoRESTService { @GET @Path("/view")
// Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/rest/UserInfoRESTService.java import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.UserInfo; package com.bitfiction.mvctemplate.rest; @Path("/userInfo") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface UserInfoRESTService { @GET @Path("/view")
public List<UserInfo> view() throws Exception;
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/UserInfoService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.UserInfo;
package com.bitfiction.mvctemplate.ejb; @Local public interface UserInfoService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/UserInfoService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.UserInfo; package com.bitfiction.mvctemplate.ejb; @Local public interface UserInfoService {
public List<UserInfo> view();
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/AccountsService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // }
import java.util.Set; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity;
package com.bitfiction.mvctemplate.ejb; @Local public interface AccountsService { public void generateAccount(String accountEmail, String accountPassword, Set<String> rolesToAdd);
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/AccountsService.java import java.util.Set; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; package com.bitfiction.mvctemplate.ejb; @Local public interface AccountsService { public void generateAccount(String accountEmail, String accountPassword, Set<String> rolesToAdd);
public void generateAccount(String accountEmail, String accountPassword, Set<String> rolesToAdd, BaseEntity baseEntity);
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/rest/impl/UserInfoRESTServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/UserInfoService.java // @Local // public interface UserInfoService { // // public List<UserInfo> view(); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/rest/UserInfoRESTService.java // @Path("/userInfo") // @Consumes(MediaType.APPLICATION_JSON) // @Produces(MediaType.APPLICATION_JSON) // public interface UserInfoRESTService { // // @GET // @Path("/view") // public List<UserInfo> view() throws Exception; // // }
import java.util.List; import javax.ejb.EJB; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import com.bitfiction.mvctemplate.ejb.UserInfoService; import com.bitfiction.mvctemplate.model.UserInfo; import com.bitfiction.mvctemplate.rest.UserInfoRESTService;
package com.bitfiction.mvctemplate.rest.impl; /** * JAX-RS Example * * This class produces a RESTful service to read the contents of the members table. */ public class UserInfoRESTServiceImpl implements UserInfoRESTService { @EJB
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/UserInfoService.java // @Local // public interface UserInfoService { // // public List<UserInfo> view(); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/rest/UserInfoRESTService.java // @Path("/userInfo") // @Consumes(MediaType.APPLICATION_JSON) // @Produces(MediaType.APPLICATION_JSON) // public interface UserInfoRESTService { // // @GET // @Path("/view") // public List<UserInfo> view() throws Exception; // // } // Path: src/main/java/com/bitfiction/mvctemplate/rest/impl/UserInfoRESTServiceImpl.java import java.util.List; import javax.ejb.EJB; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import com.bitfiction.mvctemplate.ejb.UserInfoService; import com.bitfiction.mvctemplate.model.UserInfo; import com.bitfiction.mvctemplate.rest.UserInfoRESTService; package com.bitfiction.mvctemplate.rest.impl; /** * JAX-RS Example * * This class produces a RESTful service to read the contents of the members table. */ public class UserInfoRESTServiceImpl implements UserInfoRESTService { @EJB
private UserInfoService userInfoService;
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/rest/impl/UserInfoRESTServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/UserInfoService.java // @Local // public interface UserInfoService { // // public List<UserInfo> view(); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/rest/UserInfoRESTService.java // @Path("/userInfo") // @Consumes(MediaType.APPLICATION_JSON) // @Produces(MediaType.APPLICATION_JSON) // public interface UserInfoRESTService { // // @GET // @Path("/view") // public List<UserInfo> view() throws Exception; // // }
import java.util.List; import javax.ejb.EJB; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import com.bitfiction.mvctemplate.ejb.UserInfoService; import com.bitfiction.mvctemplate.model.UserInfo; import com.bitfiction.mvctemplate.rest.UserInfoRESTService;
package com.bitfiction.mvctemplate.rest.impl; /** * JAX-RS Example * * This class produces a RESTful service to read the contents of the members table. */ public class UserInfoRESTServiceImpl implements UserInfoRESTService { @EJB private UserInfoService userInfoService; @Context private HttpServletRequest httpRequest;
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/UserInfoService.java // @Local // public interface UserInfoService { // // public List<UserInfo> view(); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/UserInfo.java // public class UserInfo { // // public UserInfo() { // super(); // } // // public UserInfo(User user, BaseEntity baseEntity, OneToOneEntity oneToOneEntity) { // super(); // this.user = user; // this.baseEntity = baseEntity; // this.oneToOneEntity = oneToOneEntity; // } // // private User user; // // private BaseEntity baseEntity; // // private OneToOneEntity oneToOneEntity; // // public User getUser() { // return user; // } // // public void setUser(User user) { // this.user = user; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/rest/UserInfoRESTService.java // @Path("/userInfo") // @Consumes(MediaType.APPLICATION_JSON) // @Produces(MediaType.APPLICATION_JSON) // public interface UserInfoRESTService { // // @GET // @Path("/view") // public List<UserInfo> view() throws Exception; // // } // Path: src/main/java/com/bitfiction/mvctemplate/rest/impl/UserInfoRESTServiceImpl.java import java.util.List; import javax.ejb.EJB; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import com.bitfiction.mvctemplate.ejb.UserInfoService; import com.bitfiction.mvctemplate.model.UserInfo; import com.bitfiction.mvctemplate.rest.UserInfoRESTService; package com.bitfiction.mvctemplate.rest.impl; /** * JAX-RS Example * * This class produces a RESTful service to read the contents of the members table. */ public class UserInfoRESTServiceImpl implements UserInfoRESTService { @EJB private UserInfoService userInfoService; @Context private HttpServletRequest httpRequest;
public List<UserInfo> view() throws Exception {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/application/ApplicationService.java
// Path: src/main/java/com/bitfiction/mvctemplate/util/OSType.java // public enum OSType { // WINDOWS, // LINUX_UNIX, // MACOS, // SOLARIS, // UNKNOWN // } // // Path: src/main/java/com/bitfiction/mvctemplate/util/OSValidator.java // public class OSValidator { // // private static String OS = System.getProperty("os.name").toLowerCase(); // // public static OSType determineOSType() { // // if (isWindows()) { // return OSType.WINDOWS; // } else if (isMac()) { // return OSType.MACOS; // } else if (isUnix()) { // return OSType.LINUX_UNIX; // } else if (isSolaris()) { // return OSType.SOLARIS; // } else { // return OSType.UNKNOWN; // } // } // // public static boolean isWindows() { // // return (OS.indexOf("win") >= 0); // // } // // public static boolean isMac() { // // return (OS.indexOf("mac") >= 0); // // } // // public static boolean isUnix() { // // return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); // // } // // public static boolean isSolaris() { // // return (OS.indexOf("sunos") >= 0); // // } // // }
import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.ejb.Singleton; import javax.ejb.Startup; import javax.inject.Inject; import com.bitfiction.mvctemplate.util.OSType; import com.bitfiction.mvctemplate.util.OSValidator;
package com.bitfiction.mvctemplate.ejb.application; @Singleton @Startup public class ApplicationService { @Inject private Logger log;
// Path: src/main/java/com/bitfiction/mvctemplate/util/OSType.java // public enum OSType { // WINDOWS, // LINUX_UNIX, // MACOS, // SOLARIS, // UNKNOWN // } // // Path: src/main/java/com/bitfiction/mvctemplate/util/OSValidator.java // public class OSValidator { // // private static String OS = System.getProperty("os.name").toLowerCase(); // // public static OSType determineOSType() { // // if (isWindows()) { // return OSType.WINDOWS; // } else if (isMac()) { // return OSType.MACOS; // } else if (isUnix()) { // return OSType.LINUX_UNIX; // } else if (isSolaris()) { // return OSType.SOLARIS; // } else { // return OSType.UNKNOWN; // } // } // // public static boolean isWindows() { // // return (OS.indexOf("win") >= 0); // // } // // public static boolean isMac() { // // return (OS.indexOf("mac") >= 0); // // } // // public static boolean isUnix() { // // return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); // // } // // public static boolean isSolaris() { // // return (OS.indexOf("sunos") >= 0); // // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/application/ApplicationService.java import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.ejb.Singleton; import javax.ejb.Startup; import javax.inject.Inject; import com.bitfiction.mvctemplate.util.OSType; import com.bitfiction.mvctemplate.util.OSValidator; package com.bitfiction.mvctemplate.ejb.application; @Singleton @Startup public class ApplicationService { @Inject private Logger log;
private OSType osType = null;
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/application/ApplicationService.java
// Path: src/main/java/com/bitfiction/mvctemplate/util/OSType.java // public enum OSType { // WINDOWS, // LINUX_UNIX, // MACOS, // SOLARIS, // UNKNOWN // } // // Path: src/main/java/com/bitfiction/mvctemplate/util/OSValidator.java // public class OSValidator { // // private static String OS = System.getProperty("os.name").toLowerCase(); // // public static OSType determineOSType() { // // if (isWindows()) { // return OSType.WINDOWS; // } else if (isMac()) { // return OSType.MACOS; // } else if (isUnix()) { // return OSType.LINUX_UNIX; // } else if (isSolaris()) { // return OSType.SOLARIS; // } else { // return OSType.UNKNOWN; // } // } // // public static boolean isWindows() { // // return (OS.indexOf("win") >= 0); // // } // // public static boolean isMac() { // // return (OS.indexOf("mac") >= 0); // // } // // public static boolean isUnix() { // // return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); // // } // // public static boolean isSolaris() { // // return (OS.indexOf("sunos") >= 0); // // } // // }
import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.ejb.Singleton; import javax.ejb.Startup; import javax.inject.Inject; import com.bitfiction.mvctemplate.util.OSType; import com.bitfiction.mvctemplate.util.OSValidator;
package com.bitfiction.mvctemplate.ejb.application; @Singleton @Startup public class ApplicationService { @Inject private Logger log; private OSType osType = null; private String fileSeparator = null; @PostConstruct public void init() { log.info("Init ApplicationService");
// Path: src/main/java/com/bitfiction/mvctemplate/util/OSType.java // public enum OSType { // WINDOWS, // LINUX_UNIX, // MACOS, // SOLARIS, // UNKNOWN // } // // Path: src/main/java/com/bitfiction/mvctemplate/util/OSValidator.java // public class OSValidator { // // private static String OS = System.getProperty("os.name").toLowerCase(); // // public static OSType determineOSType() { // // if (isWindows()) { // return OSType.WINDOWS; // } else if (isMac()) { // return OSType.MACOS; // } else if (isUnix()) { // return OSType.LINUX_UNIX; // } else if (isSolaris()) { // return OSType.SOLARIS; // } else { // return OSType.UNKNOWN; // } // } // // public static boolean isWindows() { // // return (OS.indexOf("win") >= 0); // // } // // public static boolean isMac() { // // return (OS.indexOf("mac") >= 0); // // } // // public static boolean isUnix() { // // return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); // // } // // public static boolean isSolaris() { // // return (OS.indexOf("sunos") >= 0); // // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/application/ApplicationService.java import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.ejb.Singleton; import javax.ejb.Startup; import javax.inject.Inject; import com.bitfiction.mvctemplate.util.OSType; import com.bitfiction.mvctemplate.util.OSValidator; package com.bitfiction.mvctemplate.ejb.application; @Singleton @Startup public class ApplicationService { @Inject private Logger log; private OSType osType = null; private String fileSeparator = null; @PostConstruct public void init() { log.info("Init ApplicationService");
osType = OSValidator.determineOSType();
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/web/servlet/LogoutServlet.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/User.java // @Entity // @Table(name = "user") // @SequenceGenerator(name="seqUser", initialValue=10, allocationSize=100) // public class User implements Serializable { // // // Composite-id class must implement Serializable // private static final long serialVersionUID = 1L; // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public User() { // super(); // } // // public User(String username, String password) { // this(username, password, null, null); // } // // public User(String username, String password, BaseEntity baseEntity, Set<Role> roles) { // super(); // this.username = username; // this.password = password; // this.baseEntity = baseEntity; // this.roles = roles; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqUser") // @Column(name="id") // private Long id; // // @Id // @Column(name="username", length = 127) // private String username; // // @Column(name="password", length = 127) // private String password; // // @JsonIgnore // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="baseEntityId", referencedColumnName="id") // private BaseEntity baseEntity; // // @JsonIgnore // @ManyToMany(fetch=FetchType.EAGER, cascade = {CascadeType.ALL}) // @JoinTable(name="userrole", // joinColumns={@JoinColumn(referencedColumnName="id"), // @JoinColumn(referencedColumnName="username")}, // inverseJoinColumns={@JoinColumn(referencedColumnName="id")}) // private Set<Role> roles = new HashSet<Role>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getUsername() { // return username; // } // // public void setUsername(String username) { // this.username = username; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public Set<Role> getRoles() { // return roles; // } // // public void setRoles(Set<Role> roles) { // this.roles = roles; // } // // public boolean hasRole(String rolename) { // if (this.getRoles() != null) { // for (Role role: this.getRoles()) { // if (role.getRolename().equalsIgnoreCase(rolename)) { // return true; // } // } // } // return false; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // }
import java.io.IOException; import java.util.logging.Logger; import javax.inject.Inject; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.bitfiction.mvctemplate.model.User;
package com.bitfiction.mvctemplate.web.servlet; @WebServlet("/logout") public class LogoutServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; @Inject private Logger log; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = "unknown"; if (request.getSession() != null && request.getSession().getAttribute("passuser") != null) {
// Path: src/main/java/com/bitfiction/mvctemplate/model/User.java // @Entity // @Table(name = "user") // @SequenceGenerator(name="seqUser", initialValue=10, allocationSize=100) // public class User implements Serializable { // // // Composite-id class must implement Serializable // private static final long serialVersionUID = 1L; // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public User() { // super(); // } // // public User(String username, String password) { // this(username, password, null, null); // } // // public User(String username, String password, BaseEntity baseEntity, Set<Role> roles) { // super(); // this.username = username; // this.password = password; // this.baseEntity = baseEntity; // this.roles = roles; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqUser") // @Column(name="id") // private Long id; // // @Id // @Column(name="username", length = 127) // private String username; // // @Column(name="password", length = 127) // private String password; // // @JsonIgnore // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="baseEntityId", referencedColumnName="id") // private BaseEntity baseEntity; // // @JsonIgnore // @ManyToMany(fetch=FetchType.EAGER, cascade = {CascadeType.ALL}) // @JoinTable(name="userrole", // joinColumns={@JoinColumn(referencedColumnName="id"), // @JoinColumn(referencedColumnName="username")}, // inverseJoinColumns={@JoinColumn(referencedColumnName="id")}) // private Set<Role> roles = new HashSet<Role>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getUsername() { // return username; // } // // public void setUsername(String username) { // this.username = username; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public Set<Role> getRoles() { // return roles; // } // // public void setRoles(Set<Role> roles) { // this.roles = roles; // } // // public boolean hasRole(String rolename) { // if (this.getRoles() != null) { // for (Role role: this.getRoles()) { // if (role.getRolename().equalsIgnoreCase(rolename)) { // return true; // } // } // } // return false; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/web/servlet/LogoutServlet.java import java.io.IOException; import java.util.logging.Logger; import javax.inject.Inject; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.bitfiction.mvctemplate.model.User; package com.bitfiction.mvctemplate.web.servlet; @WebServlet("/logout") public class LogoutServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; @Inject private Logger log; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = "unknown"; if (request.getSession() != null && request.getSession().getAttribute("passuser") != null) {
username = ((User) request.getSession().getAttribute("passuser")).getUsername();
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin;
package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityEditableByAdminService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin; package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityEditableByAdminService {
public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity);
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin;
package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityEditableByAdminService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin; package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityEditableByAdminService {
public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity);
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/util/DefaultExceptionHandler.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/User.java // @Entity // @Table(name = "user") // @SequenceGenerator(name="seqUser", initialValue=10, allocationSize=100) // public class User implements Serializable { // // // Composite-id class must implement Serializable // private static final long serialVersionUID = 1L; // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public User() { // super(); // } // // public User(String username, String password) { // this(username, password, null, null); // } // // public User(String username, String password, BaseEntity baseEntity, Set<Role> roles) { // super(); // this.username = username; // this.password = password; // this.baseEntity = baseEntity; // this.roles = roles; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqUser") // @Column(name="id") // private Long id; // // @Id // @Column(name="username", length = 127) // private String username; // // @Column(name="password", length = 127) // private String password; // // @JsonIgnore // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="baseEntityId", referencedColumnName="id") // private BaseEntity baseEntity; // // @JsonIgnore // @ManyToMany(fetch=FetchType.EAGER, cascade = {CascadeType.ALL}) // @JoinTable(name="userrole", // joinColumns={@JoinColumn(referencedColumnName="id"), // @JoinColumn(referencedColumnName="username")}, // inverseJoinColumns={@JoinColumn(referencedColumnName="id")}) // private Set<Role> roles = new HashSet<Role>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getUsername() { // return username; // } // // public void setUsername(String username) { // this.username = username; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public Set<Role> getRoles() { // return roles; // } // // public void setRoles(Set<Role> roles) { // this.roles = roles; // } // // public boolean hasRole(String rolename) { // if (this.getRoles() != null) { // for (Role role: this.getRoles()) { // if (role.getRolename().equalsIgnoreCase(rolename)) { // return true; // } // } // } // return false; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // }
import java.util.logging.Logger; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; import com.bitfiction.mvctemplate.model.User;
package com.bitfiction.mvctemplate.util; @Provider public class DefaultExceptionHandler implements ExceptionMapper<Exception> { @Inject private Logger log; @Context private HttpServletRequest httpRequest; @Override public Response toResponse(Exception e) { String username = "unknown"; if (httpRequest != null && httpRequest.getSession() != null && httpRequest.getSession().getAttribute("passuser") != null) {
// Path: src/main/java/com/bitfiction/mvctemplate/model/User.java // @Entity // @Table(name = "user") // @SequenceGenerator(name="seqUser", initialValue=10, allocationSize=100) // public class User implements Serializable { // // // Composite-id class must implement Serializable // private static final long serialVersionUID = 1L; // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public User() { // super(); // } // // public User(String username, String password) { // this(username, password, null, null); // } // // public User(String username, String password, BaseEntity baseEntity, Set<Role> roles) { // super(); // this.username = username; // this.password = password; // this.baseEntity = baseEntity; // this.roles = roles; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqUser") // @Column(name="id") // private Long id; // // @Id // @Column(name="username", length = 127) // private String username; // // @Column(name="password", length = 127) // private String password; // // @JsonIgnore // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="baseEntityId", referencedColumnName="id") // private BaseEntity baseEntity; // // @JsonIgnore // @ManyToMany(fetch=FetchType.EAGER, cascade = {CascadeType.ALL}) // @JoinTable(name="userrole", // joinColumns={@JoinColumn(referencedColumnName="id"), // @JoinColumn(referencedColumnName="username")}, // inverseJoinColumns={@JoinColumn(referencedColumnName="id")}) // private Set<Role> roles = new HashSet<Role>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getUsername() { // return username; // } // // public void setUsername(String username) { // this.username = username; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public Set<Role> getRoles() { // return roles; // } // // public void setRoles(Set<Role> roles) { // this.roles = roles; // } // // public boolean hasRole(String rolename) { // if (this.getRoles() != null) { // for (Role role: this.getRoles()) { // if (role.getRolename().equalsIgnoreCase(rolename)) { // return true; // } // } // } // return false; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/util/DefaultExceptionHandler.java import java.util.logging.Logger; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; import com.bitfiction.mvctemplate.model.User; package com.bitfiction.mvctemplate.util; @Provider public class DefaultExceptionHandler implements ExceptionMapper<Exception> { @Inject private Logger log; @Context private HttpServletRequest httpRequest; @Override public Response toResponse(Exception e) { String username = "unknown"; if (httpRequest != null && httpRequest.getSession() != null && httpRequest.getSession().getAttribute("passuser") != null) {
username = ((User) httpRequest.getSession().getAttribute("passuser")).getUsername();
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/rest/impl/OneToOneEntityRESTServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/User.java // @Entity // @Table(name = "user") // @SequenceGenerator(name="seqUser", initialValue=10, allocationSize=100) // public class User implements Serializable { // // // Composite-id class must implement Serializable // private static final long serialVersionUID = 1L; // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public User() { // super(); // } // // public User(String username, String password) { // this(username, password, null, null); // } // // public User(String username, String password, BaseEntity baseEntity, Set<Role> roles) { // super(); // this.username = username; // this.password = password; // this.baseEntity = baseEntity; // this.roles = roles; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqUser") // @Column(name="id") // private Long id; // // @Id // @Column(name="username", length = 127) // private String username; // // @Column(name="password", length = 127) // private String password; // // @JsonIgnore // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="baseEntityId", referencedColumnName="id") // private BaseEntity baseEntity; // // @JsonIgnore // @ManyToMany(fetch=FetchType.EAGER, cascade = {CascadeType.ALL}) // @JoinTable(name="userrole", // joinColumns={@JoinColumn(referencedColumnName="id"), // @JoinColumn(referencedColumnName="username")}, // inverseJoinColumns={@JoinColumn(referencedColumnName="id")}) // private Set<Role> roles = new HashSet<Role>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getUsername() { // return username; // } // // public void setUsername(String username) { // this.username = username; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public Set<Role> getRoles() { // return roles; // } // // public void setRoles(Set<Role> roles) { // this.roles = roles; // } // // public boolean hasRole(String rolename) { // if (this.getRoles() != null) { // for (Role role: this.getRoles()) { // if (role.getRolename().equalsIgnoreCase(rolename)) { // return true; // } // } // } // return false; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/rest/OneToOneEntityRESTService.java // @Path("/oneToOneEntity") // @Consumes(MediaType.APPLICATION_JSON) // @Produces(MediaType.APPLICATION_JSON) // public interface OneToOneEntityRESTService { // // @GET // @Path("/view") // public List<OneToOneEntity> view() throws Exception; // // @POST // @Path("/update") // public List<OneToOneEntity> update(List<OneToOneEntity> oneToOneEntities) throws Exception; // // }
import java.util.List; import javax.ejb.EJB; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.OneToOneEntity; import com.bitfiction.mvctemplate.model.User; import com.bitfiction.mvctemplate.rest.OneToOneEntityRESTService;
package com.bitfiction.mvctemplate.rest.impl; /** * JAX-RS Example * * This class produces a RESTful service to read the contents of the OneToOneEntity table. */ public class OneToOneEntityRESTServiceImpl implements OneToOneEntityRESTService { @EJB
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java // @Local // public interface OneToOneEntityService { // // public List<OneToOneEntity> view(BaseEntity baseEntity); // // public List<OneToOneEntity> update(BaseEntity baseEntity, List<OneToOneEntity> oneToOneEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/User.java // @Entity // @Table(name = "user") // @SequenceGenerator(name="seqUser", initialValue=10, allocationSize=100) // public class User implements Serializable { // // // Composite-id class must implement Serializable // private static final long serialVersionUID = 1L; // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public User() { // super(); // } // // public User(String username, String password) { // this(username, password, null, null); // } // // public User(String username, String password, BaseEntity baseEntity, Set<Role> roles) { // super(); // this.username = username; // this.password = password; // this.baseEntity = baseEntity; // this.roles = roles; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqUser") // @Column(name="id") // private Long id; // // @Id // @Column(name="username", length = 127) // private String username; // // @Column(name="password", length = 127) // private String password; // // @JsonIgnore // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="baseEntityId", referencedColumnName="id") // private BaseEntity baseEntity; // // @JsonIgnore // @ManyToMany(fetch=FetchType.EAGER, cascade = {CascadeType.ALL}) // @JoinTable(name="userrole", // joinColumns={@JoinColumn(referencedColumnName="id"), // @JoinColumn(referencedColumnName="username")}, // inverseJoinColumns={@JoinColumn(referencedColumnName="id")}) // private Set<Role> roles = new HashSet<Role>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getUsername() { // return username; // } // // public void setUsername(String username) { // this.username = username; // } // // public String getPassword() { // return password; // } // // public void setPassword(String password) { // this.password = password; // } // // public Set<Role> getRoles() { // return roles; // } // // public void setRoles(Set<Role> roles) { // this.roles = roles; // } // // public boolean hasRole(String rolename) { // if (this.getRoles() != null) { // for (Role role: this.getRoles()) { // if (role.getRolename().equalsIgnoreCase(rolename)) { // return true; // } // } // } // return false; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // // } // // Path: src/main/java/com/bitfiction/mvctemplate/rest/OneToOneEntityRESTService.java // @Path("/oneToOneEntity") // @Consumes(MediaType.APPLICATION_JSON) // @Produces(MediaType.APPLICATION_JSON) // public interface OneToOneEntityRESTService { // // @GET // @Path("/view") // public List<OneToOneEntity> view() throws Exception; // // @POST // @Path("/update") // public List<OneToOneEntity> update(List<OneToOneEntity> oneToOneEntities) throws Exception; // // } // Path: src/main/java/com/bitfiction/mvctemplate/rest/impl/OneToOneEntityRESTServiceImpl.java import java.util.List; import javax.ejb.EJB; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import com.bitfiction.mvctemplate.ejb.OneToOneEntityService; import com.bitfiction.mvctemplate.model.OneToOneEntity; import com.bitfiction.mvctemplate.model.User; import com.bitfiction.mvctemplate.rest.OneToOneEntityRESTService; package com.bitfiction.mvctemplate.rest.impl; /** * JAX-RS Example * * This class produces a RESTful service to read the contents of the OneToOneEntity table. */ public class OneToOneEntityRESTServiceImpl implements OneToOneEntityRESTService { @EJB
private OneToOneEntityService oneToOneEntityService;
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/rest/OneToOneEntityEditableByAdminRESTService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin;
package com.bitfiction.mvctemplate.rest; @Path("/oneToOneEntityEditableByAdmin") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface OneToOneEntityEditableByAdminRESTService { @GET @Path("/view")
// Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/rest/OneToOneEntityEditableByAdminRESTService.java import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin; package com.bitfiction.mvctemplate.rest; @Path("/oneToOneEntityEditableByAdmin") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface OneToOneEntityEditableByAdminRESTService { @GET @Path("/view")
public List<OneToOneEntityEditableByAdmin> view() throws Exception;
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/rest/OneToOneEntityRESTService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.OneToOneEntity;
package com.bitfiction.mvctemplate.rest; @Path("/oneToOneEntity") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface OneToOneEntityRESTService { @GET @Path("/view")
// Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/rest/OneToOneEntityRESTService.java import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.bitfiction.mvctemplate.model.OneToOneEntity; package com.bitfiction.mvctemplate.rest; @Path("/oneToOneEntity") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public interface OneToOneEntityRESTService { @GET @Path("/view")
public List<OneToOneEntity> view() throws Exception;
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/BaseEntityServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/BaseEntityService.java // @Local // public interface BaseEntityService { // // public BaseEntity findById(String id); // // public List<BaseEntity> view(); // // public List<BaseEntity> update(List<BaseEntity> baseEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.BaseEntityService; import com.bitfiction.mvctemplate.model.BaseEntity;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm")
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/BaseEntityService.java // @Local // public interface BaseEntityService { // // public BaseEntity findById(String id); // // public List<BaseEntity> view(); // // public List<BaseEntity> update(List<BaseEntity> baseEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/BaseEntityServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.BaseEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm")
public class BaseEntityServiceImpl implements BaseEntityService {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/BaseEntityServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/BaseEntityService.java // @Local // public interface BaseEntityService { // // public BaseEntity findById(String id); // // public List<BaseEntity> view(); // // public List<BaseEntity> update(List<BaseEntity> baseEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.BaseEntityService; import com.bitfiction.mvctemplate.model.BaseEntity;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class BaseEntityServiceImpl implements BaseEntityService { @Inject private EntityManager em; @Inject private Logger log; private static final String SELECT_BY_ID = "select entity from BaseEntity entity where entity.id = :id"; private static final String SELECT = "select entity from BaseEntity entity";
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/BaseEntityService.java // @Local // public interface BaseEntityService { // // public BaseEntity findById(String id); // // public List<BaseEntity> view(); // // public List<BaseEntity> update(List<BaseEntity> baseEntities); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/BaseEntityServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.BaseEntityService; import com.bitfiction.mvctemplate.model.BaseEntity; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "user" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class BaseEntityServiceImpl implements BaseEntityService { @Inject private EntityManager em; @Inject private Logger log; private static final String SELECT_BY_ID = "select entity from BaseEntity entity where entity.id = :id"; private static final String SELECT = "select entity from BaseEntity entity";
public BaseEntity findById(String id) {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/OneToManyEntityService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToManyEntity.java // @Entity // @Table(name = "OneToManyEntity") // @SequenceGenerator(name="seqOneToManyEntity", initialValue=10, allocationSize=100) // public class OneToManyEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToManyEntity() { // super(); // } // // public OneToManyEntity(String exampleString, Double exampleDouble, Integer exampleInt, Boolean exampleBool, BaseEntity baseEntity) { // super(); // this.exampleString = exampleString; // this.exampleDouble = exampleDouble; // this.exampleInt = exampleInt; // this.exampleBool = exampleBool; // this.baseEntity = baseEntity; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToManyEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // @Column(name="exampleDouble") // private Double exampleDouble; // // @Column(name="exampleInt") // private Integer exampleInt; // // @Column(name="exampleBool", columnDefinition="boolean default false") // private Boolean exampleBool; // // @ManyToOne(fetch=FetchType.LAZY) // @JoinColumns({ // @JoinColumn(name="basedentityid", referencedColumnName="id") // }) // @JsonIgnore // private BaseEntity baseEntity; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // public Double getExampleDouble() { // return exampleDouble; // } // // public void setExampleDouble(Double exampleDouble) { // this.exampleDouble = exampleDouble; // } // // public Integer getExampleInt() { // return exampleInt; // } // // public void setExampleInt(Integer exampleInt) { // this.exampleInt = exampleInt; // } // // public Boolean getExampleBool() { // return exampleBool; // } // // public void setExampleBool(Boolean exampleBool) { // this.exampleBool = exampleBool; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToManyEntity;
package com.bitfiction.mvctemplate.ejb; @Local public interface OneToManyEntityService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToManyEntity.java // @Entity // @Table(name = "OneToManyEntity") // @SequenceGenerator(name="seqOneToManyEntity", initialValue=10, allocationSize=100) // public class OneToManyEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToManyEntity() { // super(); // } // // public OneToManyEntity(String exampleString, Double exampleDouble, Integer exampleInt, Boolean exampleBool, BaseEntity baseEntity) { // super(); // this.exampleString = exampleString; // this.exampleDouble = exampleDouble; // this.exampleInt = exampleInt; // this.exampleBool = exampleBool; // this.baseEntity = baseEntity; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToManyEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // @Column(name="exampleDouble") // private Double exampleDouble; // // @Column(name="exampleInt") // private Integer exampleInt; // // @Column(name="exampleBool", columnDefinition="boolean default false") // private Boolean exampleBool; // // @ManyToOne(fetch=FetchType.LAZY) // @JoinColumns({ // @JoinColumn(name="basedentityid", referencedColumnName="id") // }) // @JsonIgnore // private BaseEntity baseEntity; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // public Double getExampleDouble() { // return exampleDouble; // } // // public void setExampleDouble(Double exampleDouble) { // this.exampleDouble = exampleDouble; // } // // public Integer getExampleInt() { // return exampleInt; // } // // public void setExampleInt(Integer exampleInt) { // this.exampleInt = exampleInt; // } // // public Boolean getExampleBool() { // return exampleBool; // } // // public void setExampleBool(Boolean exampleBool) { // this.exampleBool = exampleBool; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToManyEntityService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToManyEntity; package com.bitfiction.mvctemplate.ejb; @Local public interface OneToManyEntityService {
public List<OneToManyEntity> view(BaseEntity baseEntity);
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/OneToManyEntityService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToManyEntity.java // @Entity // @Table(name = "OneToManyEntity") // @SequenceGenerator(name="seqOneToManyEntity", initialValue=10, allocationSize=100) // public class OneToManyEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToManyEntity() { // super(); // } // // public OneToManyEntity(String exampleString, Double exampleDouble, Integer exampleInt, Boolean exampleBool, BaseEntity baseEntity) { // super(); // this.exampleString = exampleString; // this.exampleDouble = exampleDouble; // this.exampleInt = exampleInt; // this.exampleBool = exampleBool; // this.baseEntity = baseEntity; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToManyEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // @Column(name="exampleDouble") // private Double exampleDouble; // // @Column(name="exampleInt") // private Integer exampleInt; // // @Column(name="exampleBool", columnDefinition="boolean default false") // private Boolean exampleBool; // // @ManyToOne(fetch=FetchType.LAZY) // @JoinColumns({ // @JoinColumn(name="basedentityid", referencedColumnName="id") // }) // @JsonIgnore // private BaseEntity baseEntity; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // public Double getExampleDouble() { // return exampleDouble; // } // // public void setExampleDouble(Double exampleDouble) { // this.exampleDouble = exampleDouble; // } // // public Integer getExampleInt() { // return exampleInt; // } // // public void setExampleInt(Integer exampleInt) { // this.exampleInt = exampleInt; // } // // public Boolean getExampleBool() { // return exampleBool; // } // // public void setExampleBool(Boolean exampleBool) { // this.exampleBool = exampleBool; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToManyEntity;
package com.bitfiction.mvctemplate.ejb; @Local public interface OneToManyEntityService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToManyEntity.java // @Entity // @Table(name = "OneToManyEntity") // @SequenceGenerator(name="seqOneToManyEntity", initialValue=10, allocationSize=100) // public class OneToManyEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToManyEntity() { // super(); // } // // public OneToManyEntity(String exampleString, Double exampleDouble, Integer exampleInt, Boolean exampleBool, BaseEntity baseEntity) { // super(); // this.exampleString = exampleString; // this.exampleDouble = exampleDouble; // this.exampleInt = exampleInt; // this.exampleBool = exampleBool; // this.baseEntity = baseEntity; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToManyEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // @Column(name="exampleDouble") // private Double exampleDouble; // // @Column(name="exampleInt") // private Integer exampleInt; // // @Column(name="exampleBool", columnDefinition="boolean default false") // private Boolean exampleBool; // // @ManyToOne(fetch=FetchType.LAZY) // @JoinColumns({ // @JoinColumn(name="basedentityid", referencedColumnName="id") // }) // @JsonIgnore // private BaseEntity baseEntity; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // public Double getExampleDouble() { // return exampleDouble; // } // // public void setExampleDouble(Double exampleDouble) { // this.exampleDouble = exampleDouble; // } // // public Integer getExampleInt() { // return exampleInt; // } // // public void setExampleInt(Integer exampleInt) { // this.exampleInt = exampleInt; // } // // public Boolean getExampleBool() { // return exampleBool; // } // // public void setExampleBool(Boolean exampleBool) { // this.exampleBool = exampleBool; // } // // public BaseEntity getBaseEntity() { // return baseEntity; // } // // public void setBaseEntity(BaseEntity baseEntity) { // this.baseEntity = baseEntity; // } // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToManyEntityService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToManyEntity; package com.bitfiction.mvctemplate.ejb; @Local public interface OneToManyEntityService {
public List<OneToManyEntity> view(BaseEntity baseEntity);
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityEditableByAdminServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java // @Local // public interface OneToOneEntityEditableByAdminService { // // public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity); // // public List<OneToOneEntityEditableByAdmin> update(List<OneToOneEntityEditableByAdmin> oneToOneEntitiesEditableAdmin); // // public OneToOneEntityEditableByAdmin createOneToOneEntityEditableByAdminForBaseEntity(BaseEntity baseEntity); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityEditableByAdminService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "admin" }) @SecurityDomain("ExtjsMVCTemplateRealm")
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java // @Local // public interface OneToOneEntityEditableByAdminService { // // public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity); // // public List<OneToOneEntityEditableByAdmin> update(List<OneToOneEntityEditableByAdmin> oneToOneEntitiesEditableAdmin); // // public OneToOneEntityEditableByAdmin createOneToOneEntityEditableByAdminForBaseEntity(BaseEntity baseEntity); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityEditableByAdminServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityEditableByAdminService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "admin" }) @SecurityDomain("ExtjsMVCTemplateRealm")
public class OneToOneEntityEditableByAdminServiceImpl implements OneToOneEntityEditableByAdminService {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityEditableByAdminServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java // @Local // public interface OneToOneEntityEditableByAdminService { // // public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity); // // public List<OneToOneEntityEditableByAdmin> update(List<OneToOneEntityEditableByAdmin> oneToOneEntitiesEditableAdmin); // // public OneToOneEntityEditableByAdmin createOneToOneEntityEditableByAdminForBaseEntity(BaseEntity baseEntity); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityEditableByAdminService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "admin" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityEditableByAdminServiceImpl implements OneToOneEntityEditableByAdminService { @Inject private EntityManager em; @Inject private Logger log;
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java // @Local // public interface OneToOneEntityEditableByAdminService { // // public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity); // // public List<OneToOneEntityEditableByAdmin> update(List<OneToOneEntityEditableByAdmin> oneToOneEntitiesEditableAdmin); // // public OneToOneEntityEditableByAdmin createOneToOneEntityEditableByAdminForBaseEntity(BaseEntity baseEntity); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityEditableByAdminServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityEditableByAdminService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "admin" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityEditableByAdminServiceImpl implements OneToOneEntityEditableByAdminService { @Inject private EntityManager em; @Inject private Logger log;
public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity) {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityEditableByAdminServiceImpl.java
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java // @Local // public interface OneToOneEntityEditableByAdminService { // // public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity); // // public List<OneToOneEntityEditableByAdmin> update(List<OneToOneEntityEditableByAdmin> oneToOneEntitiesEditableAdmin); // // public OneToOneEntityEditableByAdmin createOneToOneEntityEditableByAdminForBaseEntity(BaseEntity baseEntity); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityEditableByAdminService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin;
package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "admin" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityEditableByAdminServiceImpl implements OneToOneEntityEditableByAdminService { @Inject private EntityManager em; @Inject private Logger log;
// Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityEditableByAdminService.java // @Local // public interface OneToOneEntityEditableByAdminService { // // public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity); // // public List<OneToOneEntityEditableByAdmin> update(List<OneToOneEntityEditableByAdmin> oneToOneEntitiesEditableAdmin); // // public OneToOneEntityEditableByAdmin createOneToOneEntityEditableByAdminForBaseEntity(BaseEntity baseEntity); // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntityEditableByAdmin.java // @Entity // @Table(name = "OneToOneEntityEditableByAdmin") // @SequenceGenerator(name="seqOneToOneEntityEditableByAdmin", initialValue=10, allocationSize=100) // public class OneToOneEntityEditableByAdmin { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntityEditableByAdmin() { // super(); // } // // public OneToOneEntityEditableByAdmin(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntityEditableByAdmin") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/impl/OneToOneEntityEditableByAdminServiceImpl.java import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import org.jboss.ejb3.annotation.SecurityDomain; import com.bitfiction.mvctemplate.ejb.OneToOneEntityEditableByAdminService; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntityEditableByAdmin; package com.bitfiction.mvctemplate.ejb.impl; @Stateless @RolesAllowed({ "admin" }) @SecurityDomain("ExtjsMVCTemplateRealm") public class OneToOneEntityEditableByAdminServiceImpl implements OneToOneEntityEditableByAdminService { @Inject private EntityManager em; @Inject private Logger log;
public List<OneToOneEntityEditableByAdmin> view(BaseEntity baseEntity) {
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/BaseEntityService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity;
package com.bitfiction.mvctemplate.ejb; @Local public interface BaseEntityService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/BaseEntityService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; package com.bitfiction.mvctemplate.ejb; @Local public interface BaseEntityService {
public BaseEntity findById(String id);
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity;
package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity; package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityService {
public List<OneToOneEntity> view(BaseEntity baseEntity);
bitfiction/extjs-mvc-rest-java-hibernate-application-template
src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // }
import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity;
package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityService {
// Path: src/main/java/com/bitfiction/mvctemplate/model/BaseEntity.java // @Entity // @Table(name = "BaseEntity") // @SequenceGenerator(name="seqBaseEntity", initialValue=10, allocationSize=100) // public class BaseEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public BaseEntity() { // super(); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this(oneToOneEntity, OneToOneEntityEditableByAdmin, null); // } // // public BaseEntity( // OneToOneEntity oneToOneEntity, // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin, // Set<OneToManyEntity> oneToManyEntities) { // super(); // this.oneToOneEntity = oneToOneEntity; // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // this.oneToManyEntities = oneToManyEntities; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqBaseEntity") // @Column(name="id") // private Long id; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityId", referencedColumnName="id") // private OneToOneEntity oneToOneEntity; // // @OneToOne(fetch=FetchType.EAGER, optional=true) // @JoinColumn(name="oneToOneEntityEditableByAdminId", referencedColumnName="id") // private OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin; // // @JsonIgnore // @OneToMany(mappedBy="baseEntity", fetch=FetchType.LAZY) // private Set<OneToManyEntity> oneToManyEntities = new HashSet<OneToManyEntity>(); // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public OneToOneEntity getOneToOneEntity() { // return oneToOneEntity; // } // // public void setOneToOneEntity(OneToOneEntity oneToOneEntity) { // this.oneToOneEntity = oneToOneEntity; // } // // public OneToOneEntityEditableByAdmin getOneToOneEntityEditableByAdmin() { // return OneToOneEntityEditableByAdmin; // } // // public void setOneToOneEntityEditableByAdmin( // OneToOneEntityEditableByAdmin OneToOneEntityEditableByAdmin) { // this.OneToOneEntityEditableByAdmin = OneToOneEntityEditableByAdmin; // } // // public Set<OneToManyEntity> getOneToManyEntities() { // return oneToManyEntities; // } // // public void setOneToManyEntities(Set<OneToManyEntity> oneToManyEntities) { // this.oneToManyEntities = oneToManyEntities; // } // // // } // // Path: src/main/java/com/bitfiction/mvctemplate/model/OneToOneEntity.java // @Entity // @Table(name = "OneToOneEntity") // @SequenceGenerator(name="seqOneToOneEntity", initialValue=10, allocationSize=100) // public class OneToOneEntity { // // // Avoid org.hibernate.InstantiationException: No default constructor for entity // public OneToOneEntity() { // super(); // } // // public OneToOneEntity(String exampleString) { // super(); // this.exampleString = exampleString; // } // // @Id // @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seqOneToOneEntity") // @Column(name="id") // private Long id; // // @Column(name="exampleString") // private String exampleString; // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getExampleString() { // return exampleString; // } // // public void setExampleString(String exampleString) { // this.exampleString = exampleString; // } // // } // Path: src/main/java/com/bitfiction/mvctemplate/ejb/OneToOneEntityService.java import java.util.List; import javax.ejb.Local; import com.bitfiction.mvctemplate.model.BaseEntity; import com.bitfiction.mvctemplate.model.OneToOneEntity; package com.bitfiction.mvctemplate.ejb; @Local public interface OneToOneEntityService {
public List<OneToOneEntity> view(BaseEntity baseEntity);
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import javax.inject.Inject; import javax.inject.Singleton;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class AppViewModelFactory implements ViewModelFactory { @Inject AppViewModelFactory() { } @NonNull @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import javax.inject.Inject; import javax.inject.Singleton; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class AppViewModelFactory implements ViewModelFactory { @Inject AppViewModelFactory() { } @NonNull @Override
public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent,
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import javax.inject.Inject; import javax.inject.Singleton;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class AppViewModelFactory implements ViewModelFactory { @Inject AppViewModelFactory() { } @NonNull @Override public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent,
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import javax.inject.Inject; import javax.inject.Singleton; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class AppViewModelFactory implements ViewModelFactory { @Inject AppViewModelFactory() { } @NonNull @Override public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent,
@Nullable ViewModel.State savedViewModelState) {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import javax.inject.Inject; import javax.inject.Singleton;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class AppViewModelFactory implements ViewModelFactory { @Inject AppViewModelFactory() { } @NonNull @Override public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { return new MainViewModel(activityComponent, savedViewModelState); } @NonNull @Override public ClickCountViewModel createClickCountViewModel( @NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { return new ClickCountViewModel(activityComponent, savedViewModelState); } @NonNull @Override public AndroidVersionsViewModel createAndroidVersionsViewModel(
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import javax.inject.Inject; import javax.inject.Singleton; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class AppViewModelFactory implements ViewModelFactory { @Inject AppViewModelFactory() { } @NonNull @Override public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { return new MainViewModel(activityComponent, savedViewModelState); } @NonNull @Override public ClickCountViewModel createClickCountViewModel( @NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { return new ClickCountViewModel(activityComponent, savedViewModelState); } @NonNull @Override public AndroidVersionsViewModel createAndroidVersionsViewModel(
@NonNull AndroidVersionsAdapter adapter,
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/TestModule.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // }
import android.content.Context; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; import static org.mockito.Mockito.mock;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public final class TestModule { @Provides @Singleton @AppContext Context provideAppContext() { return mock(Context.class); } @Provides @Singleton
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/TestModule.java import android.content.Context; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; import static org.mockito.Mockito.mock; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public final class TestModule { @Provides @Singleton @AppContext Context provideAppContext() { return mock(Context.class); } @Provides @Singleton
AttachedActivity provideAttachedActivity() {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/activity/MainActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModel.java // public class MainViewModel extends ViewModel { // // MainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // super(activityComponent, savedInstanceState); // } // // public void onClickButtonClicks() { // attachedActivity.startActivity(ClickCountActivity.class); // } // // public void onClickButtonRecyclerView() { // attachedActivity.startActivity(AndroidVersionsActivity.class); // } // // public void onClickHiBrianLee() { // try { // attachedActivity.openUrl(appContext.getString(R.string.twitter_url)); // } catch (URISyntaxException e) { // e.printStackTrace(); // } // } // }
import android.os.Bundle; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.viewmodel.MainViewModel; import butterknife.ButterKnife; import butterknife.OnClick;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class MainActivity extends BaseActivity { private MainViewModel mainViewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); } @Nullable @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModel.java // public class MainViewModel extends ViewModel { // // MainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // super(activityComponent, savedInstanceState); // } // // public void onClickButtonClicks() { // attachedActivity.startActivity(ClickCountActivity.class); // } // // public void onClickButtonRecyclerView() { // attachedActivity.startActivity(AndroidVersionsActivity.class); // } // // public void onClickHiBrianLee() { // try { // attachedActivity.openUrl(appContext.getString(R.string.twitter_url)); // } catch (URISyntaxException e) { // e.printStackTrace(); // } // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/MainActivity.java import android.os.Bundle; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.viewmodel.MainViewModel; import butterknife.ButterKnife; import butterknife.OnClick; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class MainActivity extends BaseActivity { private MainViewModel mainViewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); } @Nullable @Override
protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) {
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModelTest.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // }
import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Test; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModelTest extends ViewModelTest<MainViewModel> { @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModelTest.java import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Test; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModelTest extends ViewModelTest<MainViewModel> { @Override
protected MainViewModel createViewModel(ViewModel.State savedInstanceState) {
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModelTest.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // }
import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Test; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModelTest extends ViewModelTest<MainViewModel> { @Override protected MainViewModel createViewModel(ViewModel.State savedInstanceState) { return new MainViewModel(testComponent, null); } @Test public void testOnClickButtonClicks() { viewModel.onClickButtonClicks();
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModelTest.java import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Test; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModelTest extends ViewModelTest<MainViewModel> { @Override protected MainViewModel createViewModel(ViewModel.State savedInstanceState) { return new MainViewModel(testComponent, null); } @Test public void testOnClickButtonClicks() { viewModel.onClickButtonClicks();
verify(attachedActivity).startActivity(ClickCountActivity.class);
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModelTest.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // }
import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Test; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModelTest extends ViewModelTest<MainViewModel> { @Override protected MainViewModel createViewModel(ViewModel.State savedInstanceState) { return new MainViewModel(testComponent, null); } @Test public void testOnClickButtonClicks() { viewModel.onClickButtonClicks(); verify(attachedActivity).startActivity(ClickCountActivity.class); } @Test public void testOnClickButtonRecyclerView() { viewModel.onClickButtonRecyclerView();
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModelTest.java import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Test; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModelTest extends ViewModelTest<MainViewModel> { @Override protected MainViewModel createViewModel(ViewModel.State savedInstanceState) { return new MainViewModel(testComponent, null); } @Test public void testOnClickButtonClicks() { viewModel.onClickButtonClicks(); verify(attachedActivity).startActivity(ClickCountActivity.class); } @Test public void testOnClickButtonRecyclerView() { viewModel.onClickButtonRecyclerView();
verify(attachedActivity).startActivity(AndroidVersionsActivity.class);
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountViewModelTest.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.R; import org.junit.Test; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class ClickCountViewModelTest extends ViewModelTest<ClickCountViewModel> { private static final String TWITTER_URL = "twitterUrl"; @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountViewModelTest.java import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.R; import org.junit.Test; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class ClickCountViewModelTest extends ViewModelTest<ClickCountViewModel> { private static final String TWITTER_URL = "twitterUrl"; @Override
protected ClickCountViewModel createViewModel(ViewModel.State savedInstanceState) {
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/RecyclerViewViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/adapter/RecyclerViewAdapter.java // public abstract class RecyclerViewAdapter<ITEM_T, VIEW_MODEL_T extends ItemViewModel<ITEM_T>> // extends RecyclerView.Adapter<RecyclerViewAdapter.ItemViewHolder<ITEM_T, VIEW_MODEL_T>> { // // protected final ArrayList<ITEM_T> items; // // private final ActivityComponent activityComponent; // // public RecyclerViewAdapter(@NonNull ActivityComponent activityComponent) { // this.activityComponent = activityComponent; // items = new ArrayList<>(); // } // // @Override // public final void onBindViewHolder(ItemViewHolder<ITEM_T, VIEW_MODEL_T> holder, int position) { // holder.setItem(items.get(position)); // } // // @Override // public int getItemCount() { // return items.size(); // } // // protected final ActivityComponent getActivityComponent() { // return activityComponent; // } // // public static class ItemViewHolder<T, VT extends ItemViewModel<T>> // extends RecyclerView.ViewHolder { // // protected final VT viewModel; // private final ViewDataBinding binding; // // public ItemViewHolder(View itemView, ViewDataBinding binding, VT viewModel) { // super(itemView); // this.binding = binding; // this.viewModel = viewModel; // } // // void setItem(T item) { // viewModel.setItem(item); // binding.executePendingBindings(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // }
import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import com.hibrianlee.mvvmapp.adapter.RecyclerViewAdapter; import com.hibrianlee.mvvmapp.inject.ActivityComponent;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class RecyclerViewViewModel extends ViewModel { RecyclerView.LayoutManager layoutManager; private Parcelable savedLayoutManagerState;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/adapter/RecyclerViewAdapter.java // public abstract class RecyclerViewAdapter<ITEM_T, VIEW_MODEL_T extends ItemViewModel<ITEM_T>> // extends RecyclerView.Adapter<RecyclerViewAdapter.ItemViewHolder<ITEM_T, VIEW_MODEL_T>> { // // protected final ArrayList<ITEM_T> items; // // private final ActivityComponent activityComponent; // // public RecyclerViewAdapter(@NonNull ActivityComponent activityComponent) { // this.activityComponent = activityComponent; // items = new ArrayList<>(); // } // // @Override // public final void onBindViewHolder(ItemViewHolder<ITEM_T, VIEW_MODEL_T> holder, int position) { // holder.setItem(items.get(position)); // } // // @Override // public int getItemCount() { // return items.size(); // } // // protected final ActivityComponent getActivityComponent() { // return activityComponent; // } // // public static class ItemViewHolder<T, VT extends ItemViewModel<T>> // extends RecyclerView.ViewHolder { // // protected final VT viewModel; // private final ViewDataBinding binding; // // public ItemViewHolder(View itemView, ViewDataBinding binding, VT viewModel) { // super(itemView); // this.binding = binding; // this.viewModel = viewModel; // } // // void setItem(T item) { // viewModel.setItem(item); // binding.executePendingBindings(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/RecyclerViewViewModel.java import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import com.hibrianlee.mvvmapp.adapter.RecyclerViewAdapter; import com.hibrianlee.mvvmapp.inject.ActivityComponent; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class RecyclerViewViewModel extends ViewModel { RecyclerView.LayoutManager layoutManager; private Parcelable savedLayoutManagerState;
protected abstract RecyclerViewAdapter getAdapter();
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/RecyclerViewViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/adapter/RecyclerViewAdapter.java // public abstract class RecyclerViewAdapter<ITEM_T, VIEW_MODEL_T extends ItemViewModel<ITEM_T>> // extends RecyclerView.Adapter<RecyclerViewAdapter.ItemViewHolder<ITEM_T, VIEW_MODEL_T>> { // // protected final ArrayList<ITEM_T> items; // // private final ActivityComponent activityComponent; // // public RecyclerViewAdapter(@NonNull ActivityComponent activityComponent) { // this.activityComponent = activityComponent; // items = new ArrayList<>(); // } // // @Override // public final void onBindViewHolder(ItemViewHolder<ITEM_T, VIEW_MODEL_T> holder, int position) { // holder.setItem(items.get(position)); // } // // @Override // public int getItemCount() { // return items.size(); // } // // protected final ActivityComponent getActivityComponent() { // return activityComponent; // } // // public static class ItemViewHolder<T, VT extends ItemViewModel<T>> // extends RecyclerView.ViewHolder { // // protected final VT viewModel; // private final ViewDataBinding binding; // // public ItemViewHolder(View itemView, ViewDataBinding binding, VT viewModel) { // super(itemView); // this.binding = binding; // this.viewModel = viewModel; // } // // void setItem(T item) { // viewModel.setItem(item); // binding.executePendingBindings(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // }
import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import com.hibrianlee.mvvmapp.adapter.RecyclerViewAdapter; import com.hibrianlee.mvvmapp.inject.ActivityComponent;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class RecyclerViewViewModel extends ViewModel { RecyclerView.LayoutManager layoutManager; private Parcelable savedLayoutManagerState; protected abstract RecyclerViewAdapter getAdapter(); protected abstract RecyclerView.LayoutManager createLayoutManager();
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/adapter/RecyclerViewAdapter.java // public abstract class RecyclerViewAdapter<ITEM_T, VIEW_MODEL_T extends ItemViewModel<ITEM_T>> // extends RecyclerView.Adapter<RecyclerViewAdapter.ItemViewHolder<ITEM_T, VIEW_MODEL_T>> { // // protected final ArrayList<ITEM_T> items; // // private final ActivityComponent activityComponent; // // public RecyclerViewAdapter(@NonNull ActivityComponent activityComponent) { // this.activityComponent = activityComponent; // items = new ArrayList<>(); // } // // @Override // public final void onBindViewHolder(ItemViewHolder<ITEM_T, VIEW_MODEL_T> holder, int position) { // holder.setItem(items.get(position)); // } // // @Override // public int getItemCount() { // return items.size(); // } // // protected final ActivityComponent getActivityComponent() { // return activityComponent; // } // // public static class ItemViewHolder<T, VT extends ItemViewModel<T>> // extends RecyclerView.ViewHolder { // // protected final VT viewModel; // private final ViewDataBinding binding; // // public ItemViewHolder(View itemView, ViewDataBinding binding, VT viewModel) { // super(itemView); // this.binding = binding; // this.viewModel = viewModel; // } // // void setItem(T item) { // viewModel.setItem(item); // binding.executePendingBindings(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/RecyclerViewViewModel.java import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; import com.hibrianlee.mvvmapp.adapter.RecyclerViewAdapter; import com.hibrianlee.mvvmapp.inject.ActivityComponent; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class RecyclerViewViewModel extends ViewModel { RecyclerView.LayoutManager layoutManager; private Parcelable savedLayoutManagerState; protected abstract RecyclerViewAdapter getAdapter(); protected abstract RecyclerView.LayoutManager createLayoutManager();
public RecyclerViewViewModel(@NonNull ActivityComponent activityComponent,
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java
// Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/AndroidVersionsFragment.java // public class AndroidVersionsFragment extends BaseFragment { // // private AndroidVersionsViewModel androidVersionsViewModel; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, // Bundle savedInstanceState) { // View root = inflater.inflate(R.layout.fragment_android_versions, container, false); // ButterKnife.bind(this, root); // return root; // } // // @Nullable // @Override // protected ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // androidVersionsViewModel = viewModelFactory.createAndroidVersionsViewModel( // new AndroidVersionsAdapter(viewModelFactory, activityComponent), activityComponent, // savedViewModelState); // FragmentAndroidVersionsBinding binding = FragmentAndroidVersionsBinding.bind(root); // binding.setViewModel(androidVersionsViewModel); // return androidVersionsViewModel; // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // androidVersionsViewModel.onClickHiBrianLee(); // } // }
import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.fragment.AndroidVersionsFragment;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class AndroidVersionsActivity extends BaseActivity { private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_android_versions); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); if (fragment == null) {
// Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/AndroidVersionsFragment.java // public class AndroidVersionsFragment extends BaseFragment { // // private AndroidVersionsViewModel androidVersionsViewModel; // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, // Bundle savedInstanceState) { // View root = inflater.inflate(R.layout.fragment_android_versions, container, false); // ButterKnife.bind(this, root); // return root; // } // // @Nullable // @Override // protected ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // androidVersionsViewModel = viewModelFactory.createAndroidVersionsViewModel( // new AndroidVersionsAdapter(viewModelFactory, activityComponent), activityComponent, // savedViewModelState); // FragmentAndroidVersionsBinding binding = FragmentAndroidVersionsBinding.bind(root); // binding.setViewModel(androidVersionsViewModel); // return androidVersionsViewModel; // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // androidVersionsViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.fragment.AndroidVersionsFragment; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class AndroidVersionsActivity extends BaseActivity { private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_android_versions); FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); if (fragment == null) {
fragment = new AndroidVersionsFragment();
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AndroidVersionItemViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ItemViewModel.java // public abstract class ItemViewModel<ITEM_T> extends ViewModel { // // public ItemViewModel(@NonNull ActivityComponent activityComponent) { // super(activityComponent, null); // } // // public abstract void setItem(ITEM_T item); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/model/AndroidVersion.java // public class AndroidVersion implements Parcelable { // // private final String codeName; // private final String version; // private boolean selected; // // public AndroidVersion(String codeName, String version) { // this.codeName = codeName; // this.version = version; // } // // public AndroidVersion(Parcel in) { // codeName = in.readString(); // version = in.readString(); // selected = in.readInt() == 1; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(codeName); // dest.writeString(version); // dest.writeInt(selected ? 1 : 0); // } // // public String getCodeName() { // return codeName; // } // // public String getVersion() { // return version; // } // // public boolean isSelected() { // return selected; // } // // public void toggleSelected() { // selected = !selected; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // // AndroidVersion that = (AndroidVersion) o; // // if (selected != that.selected) return false; // if (codeName != null ? !codeName.equals(that.codeName) : that.codeName != null) // return false; // return !(version != null ? !version.equals(that.version) : that.version != null); // // } // // @Override // public int hashCode() { // int result = codeName != null ? codeName.hashCode() : 0; // result = 31 * result + (version != null ? version.hashCode() : 0); // result = 31 * result + (selected ? 1 : 0); // return result; // } // // public static Creator<AndroidVersion> CREATOR = new Creator<AndroidVersion>() { // @Override // public AndroidVersion createFromParcel(Parcel source) { // return new AndroidVersion(source); // } // // @Override // public AndroidVersion[] newArray(int size) { // return new AndroidVersion[size]; // } // }; // }
import android.databinding.Bindable; import android.support.annotation.NonNull; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ItemViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.model.AndroidVersion;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class AndroidVersionItemViewModel extends ItemViewModel<AndroidVersion> { private AndroidVersion androidVersion;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ItemViewModel.java // public abstract class ItemViewModel<ITEM_T> extends ViewModel { // // public ItemViewModel(@NonNull ActivityComponent activityComponent) { // super(activityComponent, null); // } // // public abstract void setItem(ITEM_T item); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/model/AndroidVersion.java // public class AndroidVersion implements Parcelable { // // private final String codeName; // private final String version; // private boolean selected; // // public AndroidVersion(String codeName, String version) { // this.codeName = codeName; // this.version = version; // } // // public AndroidVersion(Parcel in) { // codeName = in.readString(); // version = in.readString(); // selected = in.readInt() == 1; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(codeName); // dest.writeString(version); // dest.writeInt(selected ? 1 : 0); // } // // public String getCodeName() { // return codeName; // } // // public String getVersion() { // return version; // } // // public boolean isSelected() { // return selected; // } // // public void toggleSelected() { // selected = !selected; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // // AndroidVersion that = (AndroidVersion) o; // // if (selected != that.selected) return false; // if (codeName != null ? !codeName.equals(that.codeName) : that.codeName != null) // return false; // return !(version != null ? !version.equals(that.version) : that.version != null); // // } // // @Override // public int hashCode() { // int result = codeName != null ? codeName.hashCode() : 0; // result = 31 * result + (version != null ? version.hashCode() : 0); // result = 31 * result + (selected ? 1 : 0); // return result; // } // // public static Creator<AndroidVersion> CREATOR = new Creator<AndroidVersion>() { // @Override // public AndroidVersion createFromParcel(Parcel source) { // return new AndroidVersion(source); // } // // @Override // public AndroidVersion[] newArray(int size) { // return new AndroidVersion[size]; // } // }; // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AndroidVersionItemViewModel.java import android.databinding.Bindable; import android.support.annotation.NonNull; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ItemViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.model.AndroidVersion; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class AndroidVersionItemViewModel extends ItemViewModel<AndroidVersion> { private AndroidVersion androidVersion;
AndroidVersionItemViewModel(@NonNull ActivityComponent activityComponent) {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import java.net.URISyntaxException;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModel extends ViewModel { MainViewModel(@NonNull ActivityComponent activityComponent, @Nullable State savedInstanceState) { super(activityComponent, savedInstanceState); } public void onClickButtonClicks() {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModel.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import java.net.URISyntaxException; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModel extends ViewModel { MainViewModel(@NonNull ActivityComponent activityComponent, @Nullable State savedInstanceState) { super(activityComponent, savedInstanceState); } public void onClickButtonClicks() {
attachedActivity.startActivity(ClickCountActivity.class);
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import java.net.URISyntaxException;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModel extends ViewModel { MainViewModel(@NonNull ActivityComponent activityComponent, @Nullable State savedInstanceState) { super(activityComponent, savedInstanceState); } public void onClickButtonClicks() { attachedActivity.startActivity(ClickCountActivity.class); } public void onClickButtonRecyclerView() {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/AndroidVersionsActivity.java // public class AndroidVersionsActivity extends BaseActivity { // // private static final String TAG_VERSIONS_FRAGMENT = "versionsFragment"; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_android_versions); // // FragmentManager fm = getSupportFragmentManager(); // Fragment fragment = fm.findFragmentByTag(TAG_VERSIONS_FRAGMENT); // if (fragment == null) { // fragment = new AndroidVersionsFragment(); // fm.beginTransaction() // .add(R.id.fragmentContainer, fragment, TAG_VERSIONS_FRAGMENT) // .commit(); // } // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/MainViewModel.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.AndroidVersionsActivity; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import java.net.URISyntaxException; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainViewModel extends ViewModel { MainViewModel(@NonNull ActivityComponent activityComponent, @Nullable State savedInstanceState) { super(activityComponent, savedInstanceState); } public void onClickButtonClicks() { attachedActivity.startActivity(ClickCountActivity.class); } public void onClickButtonRecyclerView() {
attachedActivity.startActivity(AndroidVersionsActivity.class);
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MainActivityTest.java
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/BaseTest.java // public class BaseTest { // // @Inject // protected MockViewModelFactory viewModelFactory; // // @CallSuper // @Before // public void setUp() throws Exception { // Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); // MvvmSampleApplication application = (MvvmSampleApplication) instrumentation // .getTargetContext().getApplicationContext(); // TestComponent testComponent = DaggerTestComponent.builder() // .appContextModule(new AppContextModule(application)) // .build(); // application.setAppComponent(testComponent); // testComponent.inject(this); // viewModelFactory.clear(); // } // // public static Matcher<View> withRecyclerViewPosition(final int position) { // return new TypeSafeMatcher<View>() { // // @Override // public void describeTo(Description description) { // description.appendText("with RecyclerView position: " + position); // } // // @Override // protected boolean matchesSafely(View view) { // if (!(view.getParent() instanceof RecyclerView)) { // return false; // } // // RecyclerView recyclerView = (RecyclerView) view.getParent(); // RecyclerView.Adapter adapter = recyclerView.getAdapter(); // if (!(adapter instanceof RecyclerViewAdapter)) { // return false; // } // return position == recyclerView.getChildAdapterPosition(view); // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/MainActivity.java // public class MainActivity extends BaseActivity { // // private MainViewModel mainViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // mainViewModel = viewModelFactory.createMainViewModel(getActivityComponent(), // savedViewModelState); // return mainViewModel; // } // // @OnClick(R.id.buttonClicks) // void onClickButtonClicks() { // mainViewModel.onClickButtonClicks(); // } // // @OnClick(R.id.buttonRecyclerView) // void onClickButtonRecyclerView() { // mainViewModel.onClickButtonRecyclerView(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // mainViewModel.onClickHiBrianLee(); // } // }
import android.support.test.rule.ActivityTestRule; import com.hibrianlee.sample.mvvm.BaseTest; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.MainActivity; import org.junit.Rule; import org.junit.Test; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainActivityTest extends BaseTest { @Rule
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/BaseTest.java // public class BaseTest { // // @Inject // protected MockViewModelFactory viewModelFactory; // // @CallSuper // @Before // public void setUp() throws Exception { // Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); // MvvmSampleApplication application = (MvvmSampleApplication) instrumentation // .getTargetContext().getApplicationContext(); // TestComponent testComponent = DaggerTestComponent.builder() // .appContextModule(new AppContextModule(application)) // .build(); // application.setAppComponent(testComponent); // testComponent.inject(this); // viewModelFactory.clear(); // } // // public static Matcher<View> withRecyclerViewPosition(final int position) { // return new TypeSafeMatcher<View>() { // // @Override // public void describeTo(Description description) { // description.appendText("with RecyclerView position: " + position); // } // // @Override // protected boolean matchesSafely(View view) { // if (!(view.getParent() instanceof RecyclerView)) { // return false; // } // // RecyclerView recyclerView = (RecyclerView) view.getParent(); // RecyclerView.Adapter adapter = recyclerView.getAdapter(); // if (!(adapter instanceof RecyclerViewAdapter)) { // return false; // } // return position == recyclerView.getChildAdapterPosition(view); // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/MainActivity.java // public class MainActivity extends BaseActivity { // // private MainViewModel mainViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // mainViewModel = viewModelFactory.createMainViewModel(getActivityComponent(), // savedViewModelState); // return mainViewModel; // } // // @OnClick(R.id.buttonClicks) // void onClickButtonClicks() { // mainViewModel.onClickButtonClicks(); // } // // @OnClick(R.id.buttonRecyclerView) // void onClickButtonRecyclerView() { // mainViewModel.onClickButtonRecyclerView(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // mainViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MainActivityTest.java import android.support.test.rule.ActivityTestRule; import com.hibrianlee.sample.mvvm.BaseTest; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.MainActivity; import org.junit.Rule; import org.junit.Test; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class MainActivityTest extends BaseTest { @Rule
public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/AndroidVersionItemViewModelTest.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/model/AndroidVersion.java // public class AndroidVersion implements Parcelable { // // private final String codeName; // private final String version; // private boolean selected; // // public AndroidVersion(String codeName, String version) { // this.codeName = codeName; // this.version = version; // } // // public AndroidVersion(Parcel in) { // codeName = in.readString(); // version = in.readString(); // selected = in.readInt() == 1; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(codeName); // dest.writeString(version); // dest.writeInt(selected ? 1 : 0); // } // // public String getCodeName() { // return codeName; // } // // public String getVersion() { // return version; // } // // public boolean isSelected() { // return selected; // } // // public void toggleSelected() { // selected = !selected; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // // AndroidVersion that = (AndroidVersion) o; // // if (selected != that.selected) return false; // if (codeName != null ? !codeName.equals(that.codeName) : that.codeName != null) // return false; // return !(version != null ? !version.equals(that.version) : that.version != null); // // } // // @Override // public int hashCode() { // int result = codeName != null ? codeName.hashCode() : 0; // result = 31 * result + (version != null ? version.hashCode() : 0); // result = 31 * result + (selected ? 1 : 0); // return result; // } // // public static Creator<AndroidVersion> CREATOR = new Creator<AndroidVersion>() { // @Override // public AndroidVersion createFromParcel(Parcel source) { // return new AndroidVersion(source); // } // // @Override // public AndroidVersion[] newArray(int size) { // return new AndroidVersion[size]; // } // }; // }
import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.model.AndroidVersion; import org.junit.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class AndroidVersionItemViewModelTest extends ViewModelTest<AndroidVersionItemViewModel> { private AndroidVersion androidVersion; @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/model/AndroidVersion.java // public class AndroidVersion implements Parcelable { // // private final String codeName; // private final String version; // private boolean selected; // // public AndroidVersion(String codeName, String version) { // this.codeName = codeName; // this.version = version; // } // // public AndroidVersion(Parcel in) { // codeName = in.readString(); // version = in.readString(); // selected = in.readInt() == 1; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(codeName); // dest.writeString(version); // dest.writeInt(selected ? 1 : 0); // } // // public String getCodeName() { // return codeName; // } // // public String getVersion() { // return version; // } // // public boolean isSelected() { // return selected; // } // // public void toggleSelected() { // selected = !selected; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // // AndroidVersion that = (AndroidVersion) o; // // if (selected != that.selected) return false; // if (codeName != null ? !codeName.equals(that.codeName) : that.codeName != null) // return false; // return !(version != null ? !version.equals(that.version) : that.version != null); // // } // // @Override // public int hashCode() { // int result = codeName != null ? codeName.hashCode() : 0; // result = 31 * result + (version != null ? version.hashCode() : 0); // result = 31 * result + (selected ? 1 : 0); // return result; // } // // public static Creator<AndroidVersion> CREATOR = new Creator<AndroidVersion>() { // @Override // public AndroidVersion createFromParcel(Parcel source) { // return new AndroidVersion(source); // } // // @Override // public AndroidVersion[] newArray(int size) { // return new AndroidVersion[size]; // } // }; // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/viewmodel/AndroidVersionItemViewModelTest.java import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.model.AndroidVersion; import org.junit.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class AndroidVersionItemViewModelTest extends ViewModelTest<AndroidVersionItemViewModel> { private AndroidVersion androidVersion; @Override
protected AndroidVersionItemViewModel createViewModel(ViewModel.State savedInstanceState) {
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/adapter/RecyclerViewAdapter.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ItemViewModel.java // public abstract class ItemViewModel<ITEM_T> extends ViewModel { // // public ItemViewModel(@NonNull ActivityComponent activityComponent) { // super(activityComponent, null); // } // // public abstract void setItem(ITEM_T item); // }
import android.databinding.ViewDataBinding; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.View; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ItemViewModel; import java.util.ArrayList;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.adapter; public abstract class RecyclerViewAdapter<ITEM_T, VIEW_MODEL_T extends ItemViewModel<ITEM_T>> extends RecyclerView.Adapter<RecyclerViewAdapter.ItemViewHolder<ITEM_T, VIEW_MODEL_T>> { protected final ArrayList<ITEM_T> items;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ItemViewModel.java // public abstract class ItemViewModel<ITEM_T> extends ViewModel { // // public ItemViewModel(@NonNull ActivityComponent activityComponent) { // super(activityComponent, null); // } // // public abstract void setItem(ITEM_T item); // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/adapter/RecyclerViewAdapter.java import android.databinding.ViewDataBinding; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.View; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ItemViewModel; import java.util.ArrayList; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.adapter; public abstract class RecyclerViewAdapter<ITEM_T, VIEW_MODEL_T extends ItemViewModel<ITEM_T>> extends RecyclerView.Adapter<RecyclerViewAdapter.ItemViewHolder<ITEM_T, VIEW_MODEL_T>> { protected final ArrayList<ITEM_T> items;
private final ActivityComponent activityComponent;
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountActivityTest.java
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/BaseTest.java // public class BaseTest { // // @Inject // protected MockViewModelFactory viewModelFactory; // // @CallSuper // @Before // public void setUp() throws Exception { // Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); // MvvmSampleApplication application = (MvvmSampleApplication) instrumentation // .getTargetContext().getApplicationContext(); // TestComponent testComponent = DaggerTestComponent.builder() // .appContextModule(new AppContextModule(application)) // .build(); // application.setAppComponent(testComponent); // testComponent.inject(this); // viewModelFactory.clear(); // } // // public static Matcher<View> withRecyclerViewPosition(final int position) { // return new TypeSafeMatcher<View>() { // // @Override // public void describeTo(Description description) { // description.appendText("with RecyclerView position: " + position); // } // // @Override // protected boolean matchesSafely(View view) { // if (!(view.getParent() instanceof RecyclerView)) { // return false; // } // // RecyclerView recyclerView = (RecyclerView) view.getParent(); // RecyclerView.Adapter adapter = recyclerView.getAdapter(); // if (!(adapter instanceof RecyclerViewAdapter)) { // return false; // } // return position == recyclerView.getChildAdapterPosition(view); // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // }
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import android.support.test.rule.ActivityTestRule; import com.hibrianlee.sample.mvvm.BaseTest; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Rule; import org.junit.Test; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class ClickCountActivityTest extends BaseTest { @Rule
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/BaseTest.java // public class BaseTest { // // @Inject // protected MockViewModelFactory viewModelFactory; // // @CallSuper // @Before // public void setUp() throws Exception { // Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); // MvvmSampleApplication application = (MvvmSampleApplication) instrumentation // .getTargetContext().getApplicationContext(); // TestComponent testComponent = DaggerTestComponent.builder() // .appContextModule(new AppContextModule(application)) // .build(); // application.setAppComponent(testComponent); // testComponent.inject(this); // viewModelFactory.clear(); // } // // public static Matcher<View> withRecyclerViewPosition(final int position) { // return new TypeSafeMatcher<View>() { // // @Override // public void describeTo(Description description) { // description.appendText("with RecyclerView position: " + position); // } // // @Override // protected boolean matchesSafely(View view) { // if (!(view.getParent() instanceof RecyclerView)) { // return false; // } // // RecyclerView recyclerView = (RecyclerView) view.getParent(); // RecyclerView.Adapter adapter = recyclerView.getAdapter(); // if (!(adapter instanceof RecyclerViewAdapter)) { // return false; // } // return position == recyclerView.getChildAdapterPosition(view); // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java // public class ClickCountActivity extends BaseActivity { // // private ClickCountViewModel clickCountViewModel; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // ActivityClickCountBinding binding = // DataBindingUtil.setContentView(this, R.layout.activity_click_count); // binding.setViewModel(clickCountViewModel); // ButterKnife.bind(this); // } // // @Nullable // @Override // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = viewModelFactory.createClickCountViewModel(getActivityComponent(), // savedViewModelState); // return clickCountViewModel; // } // // @OnClick(R.id.clickButton) // void onClickButton() { // clickCountViewModel.onClickButton(); // } // // @OnClick(R.id.hiBrianLee) // void onClickHiBrianLee() { // clickCountViewModel.onClickHiBrianLee(); // } // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountActivityTest.java import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import android.support.test.rule.ActivityTestRule; import com.hibrianlee.sample.mvvm.BaseTest; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.activity.ClickCountActivity; import org.junit.Rule; import org.junit.Test; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class ClickCountActivityTest extends BaseTest { @Rule
public ActivityTestRule<ClickCountActivity> activityTestRule = new ActivityTestRule<>(
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";
private ViewModel viewModel;
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ViewModel viewModel;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ViewModel viewModel;
protected void inject(AppComponent appComponent) {
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Nullable protected abstract ViewModel createAndBindViewModel(View root,
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Nullable protected abstract ViewModel createAndBindViewModel(View root,
@NonNull ActivityComponent activityComponent,
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Nullable protected abstract ViewModel createAndBindViewModel(View root, @NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState); @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppComponent appComponent =
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.View; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.fragment; public abstract class ViewModelFragment extends Fragment { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Nullable protected abstract ViewModel createAndBindViewModel(View root, @NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState); @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppComponent appComponent =
((MvvmApplication) getActivity().getApplication()).getAppComponent();
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public interface ViewModelFactory { @NonNull
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public interface ViewModelFactory { @NonNull
MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent,
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public interface ViewModelFactory { @NonNull MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent,
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public interface ViewModelFactory { @NonNull MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent,
@Nullable ViewModel.State savedViewModelState);
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public interface ViewModelFactory { @NonNull MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState); @NonNull ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState); @NonNull AndroidVersionsViewModel createAndroidVersionsViewModel(
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public interface ViewModelFactory { @NonNull MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState); @NonNull ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState); @NonNull AndroidVersionsViewModel createAndroidVersionsViewModel(
@NonNull AndroidVersionsAdapter adapter,
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import static org.mockito.Mockito.spy; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; import static org.mockito.Mockito.doNothing;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class MockViewModelFactory implements ViewModelFactory {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java import static org.mockito.Mockito.spy; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; import static org.mockito.Mockito.doNothing; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; @Singleton public class MockViewModelFactory implements ViewModelFactory {
private final Map<Class<? extends ViewModel>, SpyInitializer<? extends ViewModel>>
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import static org.mockito.Mockito.spy; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; import static org.mockito.Mockito.doNothing;
spyInitializerMap.put(viewModelClass, spyInitializer); } @SuppressWarnings("unchecked") private <ViewModelT extends ViewModel> void setupSpy(Class<ViewModelT> viewModelClass, ViewModelT viewModel) { SpyInitializer spyInitializer = spyInitializerMap.get(viewModelClass); if (spyInitializer != null) { spyInitializer.setupSpy(viewModel); } } public MainViewModel getMainViewModel() { return mainViewModel; } public ClickCountViewModel getClickCountViewModel() { return clickCountViewModel; } public AndroidVersionsViewModel getAndroidVersionsViewModel() { return androidVersionsViewModel; } public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { return androidVersionItemViewModel; } @NonNull @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java import static org.mockito.Mockito.spy; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; import static org.mockito.Mockito.doNothing; spyInitializerMap.put(viewModelClass, spyInitializer); } @SuppressWarnings("unchecked") private <ViewModelT extends ViewModel> void setupSpy(Class<ViewModelT> viewModelClass, ViewModelT viewModel) { SpyInitializer spyInitializer = spyInitializerMap.get(viewModelClass); if (spyInitializer != null) { spyInitializer.setupSpy(viewModel); } } public MainViewModel getMainViewModel() { return mainViewModel; } public ClickCountViewModel getClickCountViewModel() { return clickCountViewModel; } public AndroidVersionsViewModel getAndroidVersionsViewModel() { return androidVersionsViewModel; } public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { return androidVersionItemViewModel; } @NonNull @Override
public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent,
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // }
import static org.mockito.Mockito.spy; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; import static org.mockito.Mockito.doNothing;
} public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { return androidVersionItemViewModel; } @NonNull @Override public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { mainViewModel = spy(new MainViewModel(activityComponent, savedViewModelState)); doNothingOnLifeCycle(mainViewModel); setupSpy(MainViewModel.class, mainViewModel); return mainViewModel; } @NonNull @Override public ClickCountViewModel createClickCountViewModel( @NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { clickCountViewModel = spy(new ClickCountViewModel(activityComponent, savedViewModelState)); doNothingOnLifeCycle(clickCountViewModel); setupSpy(ClickCountViewModel.class, clickCountViewModel); return clickCountViewModel; } @NonNull @Override public AndroidVersionsViewModel createAndroidVersionsViewModel(
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/adapter/AndroidVersionsAdapter.java // public class AndroidVersionsAdapter // extends RecyclerViewAdapter<AndroidVersion, AndroidVersionItemViewModel> { // // private final ViewModelFactory viewModelFactory; // // public AndroidVersionsAdapter(ViewModelFactory viewModelFactory, // @NonNull ActivityComponent activityComponent) { // super(activityComponent); // this.viewModelFactory = viewModelFactory; // } // // @Override // public AndroidVersionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View itemView = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.item_android_version, parent, false); // // AndroidVersionItemViewModel viewModel = // viewModelFactory.createAndroidVersionItemViewModel(getActivityComponent()); // // ItemAndroidVersionBinding binding = ItemAndroidVersionBinding.bind(itemView); // binding.setViewModel(viewModel); // // return new AndroidVersionViewHolder(itemView, binding, viewModel); // } // // public void setItems(ArrayList<AndroidVersion> newItems) { // items.clear(); // items.addAll(newItems); // notifyDataSetChanged(); // } // // public ArrayList<AndroidVersion> getItems() { // return items; // } // // static class AndroidVersionViewHolder // extends ItemViewHolder<AndroidVersion, AndroidVersionItemViewModel> { // // public AndroidVersionViewHolder(View itemView, ViewDataBinding binding, // AndroidVersionItemViewModel viewModel) { // super(itemView, binding, viewModel); // ButterKnife.bind(this, itemView); // } // // @OnClick(R.id.versionItem) // void onClickVersionItem() { // viewModel.onClick(); // } // } // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java import static org.mockito.Mockito.spy; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.adapter.AndroidVersionsAdapter; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; import static org.mockito.Mockito.doNothing; } public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { return androidVersionItemViewModel; } @NonNull @Override public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { mainViewModel = spy(new MainViewModel(activityComponent, savedViewModelState)); doNothingOnLifeCycle(mainViewModel); setupSpy(MainViewModel.class, mainViewModel); return mainViewModel; } @NonNull @Override public ClickCountViewModel createClickCountViewModel( @NonNull ActivityComponent activityComponent, @Nullable ViewModel.State savedViewModelState) { clickCountViewModel = spy(new ClickCountViewModel(activityComponent, savedViewModelState)); doNothingOnLifeCycle(clickCountViewModel); setupSpy(ClickCountViewModel.class, clickCountViewModel); return clickCountViewModel; } @NonNull @Override public AndroidVersionsViewModel createAndroidVersionsViewModel(
@NonNull AndroidVersionsAdapter adapter,
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState";
private ActivityComponent activityComponent;
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent;
private ViewModel viewModel;
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent; private ViewModel viewModel;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent; private ViewModel viewModel;
protected void inject(AppComponent appComponent) {
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent();
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); inject(appComponent); activityComponent = DaggerActivityComponent.builder() .appComponent(appComponent)
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java // @Module // public final class ActivityModule { // // private final ViewModelActivity activity; // // public ActivityModule(ViewModelActivity activity) { // this.activity = activity; // } // // @Provides // @PerActivity // AttachedActivity provideAttachedActivity() { // return new AttachedViewModelActivity(activity); // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.ActivityModule; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.DaggerActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.activity; public abstract class ViewModelActivity extends AppCompatActivity { private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; private ActivityComponent activityComponent; private ViewModel viewModel; protected void inject(AppComponent appComponent) { appComponent.inject(this); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); inject(appComponent); activityComponent = DaggerActivityComponent.builder() .appComponent(appComponent)
.activityModule(new ActivityModule(this))
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/TestComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // }
import com.hibrianlee.mvvmapp.inject.AppContextModule; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/TestComponent.java import com.hibrianlee.mvvmapp.inject.AppContextModule; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = {
AppContextModule.class,
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/MockModule.java
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java // @Singleton // public class MockViewModelFactory implements ViewModelFactory { // // private final Map<Class<? extends ViewModel>, SpyInitializer<? extends ViewModel>> // spyInitializerMap; // // private MainViewModel mainViewModel; // private ClickCountViewModel clickCountViewModel; // private AndroidVersionsViewModel androidVersionsViewModel; // private AndroidVersionItemViewModel androidVersionItemViewModel; // // public interface SpyInitializer<ViewModelT extends ViewModel> { // void setupSpy(ViewModelT viewModel); // } // // @Inject // MockViewModelFactory() { // spyInitializerMap = new HashMap<>(); // } // // public void clear() { // spyInitializerMap.clear(); // mainViewModel = null; // clickCountViewModel = null; // androidVersionsViewModel = null; // androidVersionItemViewModel = null; // } // // public <ViewModelT extends ViewModel> void registerSpyInitializer( // Class<ViewModelT> viewModelClass, SpyInitializer<ViewModelT> spyInitializer) { // spyInitializerMap.put(viewModelClass, spyInitializer); // } // // @SuppressWarnings("unchecked") // private <ViewModelT extends ViewModel> void setupSpy(Class<ViewModelT> viewModelClass, // ViewModelT viewModel) { // SpyInitializer spyInitializer = spyInitializerMap.get(viewModelClass); // if (spyInitializer != null) { // spyInitializer.setupSpy(viewModel); // } // } // // public MainViewModel getMainViewModel() { // return mainViewModel; // } // // public ClickCountViewModel getClickCountViewModel() { // return clickCountViewModel; // } // // public AndroidVersionsViewModel getAndroidVersionsViewModel() { // return androidVersionsViewModel; // } // // public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { // return androidVersionItemViewModel; // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // mainViewModel = spy(new MainViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(mainViewModel); // setupSpy(MainViewModel.class, mainViewModel); // return mainViewModel; // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = spy(new ClickCountViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(clickCountViewModel); // setupSpy(ClickCountViewModel.class, clickCountViewModel); // return clickCountViewModel; // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // androidVersionsViewModel = spy(new AndroidVersionsViewModel(adapter, activityComponent, // savedViewModelState)); // doNothingOnLifeCycle(androidVersionsViewModel); // setupSpy(AndroidVersionsViewModel.class, androidVersionsViewModel); // return androidVersionsViewModel; // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // if (androidVersionItemViewModel == null) { // androidVersionItemViewModel = spy(new AndroidVersionItemViewModel(activityComponent)); // doNothingOnLifeCycle(androidVersionItemViewModel); // setupSpy(AndroidVersionItemViewModel.class, androidVersionItemViewModel); // } // return androidVersionItemViewModel; // } // // private void doNothingOnLifeCycle(ViewModel viewModel) { // doNothing().when(viewModel).onStart(); // doNothing().when(viewModel).onStop(); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.sample.mvvm.viewmodel.MockViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class MockModule { @Provides @Singleton
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java // @Singleton // public class MockViewModelFactory implements ViewModelFactory { // // private final Map<Class<? extends ViewModel>, SpyInitializer<? extends ViewModel>> // spyInitializerMap; // // private MainViewModel mainViewModel; // private ClickCountViewModel clickCountViewModel; // private AndroidVersionsViewModel androidVersionsViewModel; // private AndroidVersionItemViewModel androidVersionItemViewModel; // // public interface SpyInitializer<ViewModelT extends ViewModel> { // void setupSpy(ViewModelT viewModel); // } // // @Inject // MockViewModelFactory() { // spyInitializerMap = new HashMap<>(); // } // // public void clear() { // spyInitializerMap.clear(); // mainViewModel = null; // clickCountViewModel = null; // androidVersionsViewModel = null; // androidVersionItemViewModel = null; // } // // public <ViewModelT extends ViewModel> void registerSpyInitializer( // Class<ViewModelT> viewModelClass, SpyInitializer<ViewModelT> spyInitializer) { // spyInitializerMap.put(viewModelClass, spyInitializer); // } // // @SuppressWarnings("unchecked") // private <ViewModelT extends ViewModel> void setupSpy(Class<ViewModelT> viewModelClass, // ViewModelT viewModel) { // SpyInitializer spyInitializer = spyInitializerMap.get(viewModelClass); // if (spyInitializer != null) { // spyInitializer.setupSpy(viewModel); // } // } // // public MainViewModel getMainViewModel() { // return mainViewModel; // } // // public ClickCountViewModel getClickCountViewModel() { // return clickCountViewModel; // } // // public AndroidVersionsViewModel getAndroidVersionsViewModel() { // return androidVersionsViewModel; // } // // public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { // return androidVersionItemViewModel; // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // mainViewModel = spy(new MainViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(mainViewModel); // setupSpy(MainViewModel.class, mainViewModel); // return mainViewModel; // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = spy(new ClickCountViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(clickCountViewModel); // setupSpy(ClickCountViewModel.class, clickCountViewModel); // return clickCountViewModel; // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // androidVersionsViewModel = spy(new AndroidVersionsViewModel(adapter, activityComponent, // savedViewModelState)); // doNothingOnLifeCycle(androidVersionsViewModel); // setupSpy(AndroidVersionsViewModel.class, androidVersionsViewModel); // return androidVersionsViewModel; // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // if (androidVersionItemViewModel == null) { // androidVersionItemViewModel = spy(new AndroidVersionItemViewModel(activityComponent)); // doNothingOnLifeCycle(androidVersionItemViewModel); // setupSpy(AndroidVersionItemViewModel.class, androidVersionItemViewModel); // } // return androidVersionItemViewModel; // } // // private void doNothingOnLifeCycle(ViewModel viewModel) { // doNothing().when(viewModel).onStart(); // doNothing().when(viewModel).onStop(); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/MockModule.java import com.hibrianlee.sample.mvvm.viewmodel.MockViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class MockModule { @Provides @Singleton
ViewModelFactory provideViewModelFactory(MockViewModelFactory mockViewModelFactory) {
hiBrianLee/AndroidMvvm
sample/src/androidTest/java/com/hibrianlee/sample/mvvm/MockModule.java
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java // @Singleton // public class MockViewModelFactory implements ViewModelFactory { // // private final Map<Class<? extends ViewModel>, SpyInitializer<? extends ViewModel>> // spyInitializerMap; // // private MainViewModel mainViewModel; // private ClickCountViewModel clickCountViewModel; // private AndroidVersionsViewModel androidVersionsViewModel; // private AndroidVersionItemViewModel androidVersionItemViewModel; // // public interface SpyInitializer<ViewModelT extends ViewModel> { // void setupSpy(ViewModelT viewModel); // } // // @Inject // MockViewModelFactory() { // spyInitializerMap = new HashMap<>(); // } // // public void clear() { // spyInitializerMap.clear(); // mainViewModel = null; // clickCountViewModel = null; // androidVersionsViewModel = null; // androidVersionItemViewModel = null; // } // // public <ViewModelT extends ViewModel> void registerSpyInitializer( // Class<ViewModelT> viewModelClass, SpyInitializer<ViewModelT> spyInitializer) { // spyInitializerMap.put(viewModelClass, spyInitializer); // } // // @SuppressWarnings("unchecked") // private <ViewModelT extends ViewModel> void setupSpy(Class<ViewModelT> viewModelClass, // ViewModelT viewModel) { // SpyInitializer spyInitializer = spyInitializerMap.get(viewModelClass); // if (spyInitializer != null) { // spyInitializer.setupSpy(viewModel); // } // } // // public MainViewModel getMainViewModel() { // return mainViewModel; // } // // public ClickCountViewModel getClickCountViewModel() { // return clickCountViewModel; // } // // public AndroidVersionsViewModel getAndroidVersionsViewModel() { // return androidVersionsViewModel; // } // // public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { // return androidVersionItemViewModel; // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // mainViewModel = spy(new MainViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(mainViewModel); // setupSpy(MainViewModel.class, mainViewModel); // return mainViewModel; // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = spy(new ClickCountViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(clickCountViewModel); // setupSpy(ClickCountViewModel.class, clickCountViewModel); // return clickCountViewModel; // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // androidVersionsViewModel = spy(new AndroidVersionsViewModel(adapter, activityComponent, // savedViewModelState)); // doNothingOnLifeCycle(androidVersionsViewModel); // setupSpy(AndroidVersionsViewModel.class, androidVersionsViewModel); // return androidVersionsViewModel; // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // if (androidVersionItemViewModel == null) { // androidVersionItemViewModel = spy(new AndroidVersionItemViewModel(activityComponent)); // doNothingOnLifeCycle(androidVersionItemViewModel); // setupSpy(AndroidVersionItemViewModel.class, androidVersionItemViewModel); // } // return androidVersionItemViewModel; // } // // private void doNothingOnLifeCycle(ViewModel viewModel) { // doNothing().when(viewModel).onStart(); // doNothing().when(viewModel).onStop(); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.sample.mvvm.viewmodel.MockViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class MockModule { @Provides @Singleton
// Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/viewmodel/MockViewModelFactory.java // @Singleton // public class MockViewModelFactory implements ViewModelFactory { // // private final Map<Class<? extends ViewModel>, SpyInitializer<? extends ViewModel>> // spyInitializerMap; // // private MainViewModel mainViewModel; // private ClickCountViewModel clickCountViewModel; // private AndroidVersionsViewModel androidVersionsViewModel; // private AndroidVersionItemViewModel androidVersionItemViewModel; // // public interface SpyInitializer<ViewModelT extends ViewModel> { // void setupSpy(ViewModelT viewModel); // } // // @Inject // MockViewModelFactory() { // spyInitializerMap = new HashMap<>(); // } // // public void clear() { // spyInitializerMap.clear(); // mainViewModel = null; // clickCountViewModel = null; // androidVersionsViewModel = null; // androidVersionItemViewModel = null; // } // // public <ViewModelT extends ViewModel> void registerSpyInitializer( // Class<ViewModelT> viewModelClass, SpyInitializer<ViewModelT> spyInitializer) { // spyInitializerMap.put(viewModelClass, spyInitializer); // } // // @SuppressWarnings("unchecked") // private <ViewModelT extends ViewModel> void setupSpy(Class<ViewModelT> viewModelClass, // ViewModelT viewModel) { // SpyInitializer spyInitializer = spyInitializerMap.get(viewModelClass); // if (spyInitializer != null) { // spyInitializer.setupSpy(viewModel); // } // } // // public MainViewModel getMainViewModel() { // return mainViewModel; // } // // public ClickCountViewModel getClickCountViewModel() { // return clickCountViewModel; // } // // public AndroidVersionsViewModel getAndroidVersionsViewModel() { // return androidVersionsViewModel; // } // // public AndroidVersionItemViewModel getAndroidVersionItemViewModel() { // return androidVersionItemViewModel; // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // mainViewModel = spy(new MainViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(mainViewModel); // setupSpy(MainViewModel.class, mainViewModel); // return mainViewModel; // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // clickCountViewModel = spy(new ClickCountViewModel(activityComponent, savedViewModelState)); // doNothingOnLifeCycle(clickCountViewModel); // setupSpy(ClickCountViewModel.class, clickCountViewModel); // return clickCountViewModel; // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // androidVersionsViewModel = spy(new AndroidVersionsViewModel(adapter, activityComponent, // savedViewModelState)); // doNothingOnLifeCycle(androidVersionsViewModel); // setupSpy(AndroidVersionsViewModel.class, androidVersionsViewModel); // return androidVersionsViewModel; // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // if (androidVersionItemViewModel == null) { // androidVersionItemViewModel = spy(new AndroidVersionItemViewModel(activityComponent)); // doNothingOnLifeCycle(androidVersionItemViewModel); // setupSpy(AndroidVersionItemViewModel.class, androidVersionItemViewModel); // } // return androidVersionItemViewModel; // } // // private void doNothingOnLifeCycle(ViewModel viewModel) { // doNothing().when(viewModel).onStart(); // doNothing().when(viewModel).onStop(); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/androidTest/java/com/hibrianlee/sample/mvvm/MockModule.java import com.hibrianlee.sample.mvvm.viewmodel.MockViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class MockModule { @Provides @Singleton
ViewModelFactory provideViewModelFactory(MockViewModelFactory mockViewModelFactory) {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.fragment; public abstract class BaseFragment extends ViewModelFragment { @Inject
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.fragment; public abstract class BaseFragment extends ViewModelFragment { @Inject
protected ViewModelFactory viewModelFactory;
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.fragment; public abstract class BaseFragment extends ViewModelFragment { @Inject protected ViewModelFactory viewModelFactory; @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.fragment; public abstract class BaseFragment extends ViewModelFragment { @Inject protected ViewModelFactory viewModelFactory; @Override
protected void inject(AppComponent appComponent) {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.fragment; public abstract class BaseFragment extends ViewModelFragment { @Inject protected ViewModelFactory viewModelFactory; @Override protected void inject(AppComponent appComponent) {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.fragment; public abstract class BaseFragment extends ViewModelFragment { @Inject protected ViewModelFactory viewModelFactory; @Override protected void inject(AppComponent appComponent) {
((SampleAppComponent) appComponent).inject(this);
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // }
import android.content.Context; import android.databinding.BaseObservable; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class ViewModel extends BaseObservable { @Inject @AppContext protected Context appContext; @Inject
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java import android.content.Context; import android.databinding.BaseObservable; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class ViewModel extends BaseObservable { @Inject @AppContext protected Context appContext; @Inject
protected AttachedActivity attachedActivity;
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // }
import android.content.Context; import android.databinding.BaseObservable; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class ViewModel extends BaseObservable { @Inject @AppContext protected Context appContext; @Inject protected AttachedActivity attachedActivity;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java import android.content.Context; import android.databinding.BaseObservable; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.viewmodel; public abstract class ViewModel extends BaseObservable { @Inject @AppContext protected Context appContext; @Inject protected AttachedActivity attachedActivity;
protected ViewModel(@NonNull ActivityComponent activityComponent,